Compare commits

...

18 Commits

Author SHA1 Message Date
xuedongliang 7ecf1af00f 1、add Framework/connection/industrial_ethernet DIR; 2、add Framework/connection/industrial_fieldbus DIR; 3、add Framework/connection/industrial_wlan DIR from Liu Weichao
it is OK
2021-12-22 13:28:42 +08:00
Liu_Weichao 60442e489a feat Framework/connection/industrial_xxx DIR 2021-12-20 16:14:02 +08:00
xuedongliang cb8c68659c 1. add sensor as830 of ch4; 2、repair a bug of requiring password in letter shell
it is OK
2021-12-16 17:40:29 +08:00
Wang_Weigen db225df433 add 'TB600B_WQ_HCHO1OS' sensor of hcho to sensor framework 2021-12-15 16:28:51 +08:00
Wang_Weigen 19edea21d7 add 'TB600B_TVOC10' sensor of tvoc to sensor framework 2021-12-15 15:01:30 +08:00
Wang_Weigen 856edb7ec6 add sensor 'TB600B_IAQ10' to sensor framework 2021-12-15 11:10:56 +08:00
Wang_Weigen 4a8ac7c02b repair ch4 test 2021-12-14 14:07:09 +08:00
Wang_Weigen e366c8817c repair a bug of inputting password of shell 2021-12-14 10:37:22 +08:00
Wang_Weigen f2ba792380 sync upstream branch and add 'as830' sensor of ch4 2021-12-14 10:32:17 +08:00
xuedongliang cc6c459e7b fix APP_Framework bugs,include sensor framework and Applications
it is OK
2021-12-13 14:18:48 +08:00
Liu_Weichao e9e9080ae0 delete useless DIR connection_app/ and app_test/ 2021-12-10 10:39:37 +08:00
Liu_Weichao ead80da91f fix that i2c device of sensor framework cannot set i2c address 2021-12-10 10:23:30 +08:00
xuedongliang c9db5635b0 add framework configuration select from Wang_Weigen 2021-12-09 11:08:00 +08:00
xuedongliang 3397a5245b Add the cortex-m0 support for XiUOS & Fix bugs on M3 and serial device from ysm
it is Perfect
2021-12-09 11:07:15 +08:00
Wang_Weigen 85cbc7717e add framework configuration select 2021-12-09 10:56:25 +08:00
Kiritoy 58060874d6 rebase prepare_for_master branch 2021-12-08 14:52:10 +08:00
Kiritoy a080d98470 Restore the file directory structure 2021-12-08 14:43:10 +08:00
Kiritoy 4aacf28974 add cortex-m0 support and fix some bugs 2021-12-08 14:43:10 +08:00
110 changed files with 6193 additions and 1061 deletions

View File

@ -4,14 +4,6 @@ menu "test app"
default n
if USER_TEST
config USER_TEST_LORA_ADHOC
bool "Config test lora adhoc"
default n
config USER_TEST_SPI_LORA
bool "Config test spi lora"
default n
config USER_TEST_SPI_FLASH
bool "Config test spi flash"
default n

View File

@ -1,13 +1,5 @@
SRC_FILES :=
ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y)
SRC_FILES += test_adhoc_lora.c
endif
ifeq ($(CONFIG_USER_TEST_SPI_LORA),y)
SRC_FILES += test_spi_lora.c
endif
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif

View File

@ -1,20 +0,0 @@
#include <xiuos.h>
extern void net_lora_client(int argc, char *argv[]);
extern void net_lora_gateway(int argc, char *argv[]);
void demo_lora_adhoc()
{
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_CLIENT
char pgk_count[32];
char* param[3];
param[0] = "xxx";
param[1] = CONNECTION_COMMUNICATION_LORA_CLIENT_NAME;
itoa(CONNECTION_COMMUNICATION_LORA_CLIENT_PKG_COUNT, pgk_count, 10);
param[2] = pgk_count;
net_lora_client(2, param);
#endif
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_GATEWAY
net_lora_gateway(0, 0);
#endif
}

View File

@ -1,3 +1,3 @@
SRC_DIR :=wifi_demo
SRC_DIR :=
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,108 +0,0 @@
#include <user_api.h>
#include <string.h>
#include <xs_adapter_lora.h>
#include <xs_adapter_manager.h>
#include <stdio.h>
#include <stdlib.h>
char client_name[DEVNAME_LEN_MAX] = "lora_dev_123";
void success_cb(void *param)
{
printf("success_cb, param = %s\n", param);
}
void invert_param(void *param)
{
printf("success_cb02 invoke, invert bool param.\n");
bool *bparam = (bool *)param;
if (*bparam)
{
*bparam = false;
}
else
{
*bparam = true;
}
}
void net_lora_client(int argc, char *argv[])
{
int pkg_count = 10;
if (argc >= 1)
{
memset(client_name, 0, DEVNAME_LEN_MAX);
strncpy(client_name, argv[1], strlen(argv[1]));
printf("lora client set clientName(%s).\n", client_name);
}
if (argc >= 2)
{
pkg_count = atoi(argv[2]);
printf("lora client set pkg_count(%d).\n", pkg_count);
}
// 1.Create an adapter for a specific agreement (LORA)
static struct AdapterLora lora_adapter;
memset(&lora_adapter, 0, sizeof(lora_adapter));
struct AdapterDone lora_example_done = {
.NetAiitOpen = LoraAdapterOpen,
.NetAiitClose = LoraAdapterCose,
.NetAiitSend = LoraAdapterSendc2g,
.NetAiitReceive = NULL,
.NetAiitJoin = LoraAdapterJoin,
.NetAiitIoctl = NULL,
};
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
lora_adapter.name = client_name; // Set adapter name
lora_adapter.spi_lora_fd = -1; // Set adapter information
lora_adapter.deve_ui = "xxx";
lora_adapter.app_key = "yyy";
// 2.Register the adapter in the list
LoraAdapterInit();
LoraAdapterRegister((adapter_t)&lora_adapter);
// 3.Find from the list of registered adapters
adapter_t padapter = LoraAdapterFind(client_name);
if (NONE == padapter)
{
printf("adapter find failed!\n");
return;
}
// 4.Open adapter
if (0 != padapter->done.NetAiitOpen(padapter))
{
printf("adapter open failed!\n");
return;
}
// 5.Join the specified network segment as client
printf("NetAiitJoin start. \n");
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_SLAVE, CONNECTION_COMMUNICATION_LORA_NET_ID);
printf("NetAiitJoin end. \n");
// 6.Point to point sending data to gateway
int i = 0;
while (i < pkg_count)
{
char data[120] = {0};
sprintf(data, "***** I am %s, data_num = %d ******" ,client_name, i);
bool v = false;
padapter->done.NetAiitSend(padapter, data, strlen(data) + 1, true, 10000, 0, invert_param, &v, NULL);
while (!v) // Asynchronous analog synchronization
{
UserTaskDelay(100);
}
printf("send success(main thread)... %s\n" ,data);
i++;
UserTaskDelay(800); // Contract interval
}
printf("all pkg send success(main thread), quit.\n");
padapter->done.NetAiitClose(padapter);
printf("client quit.\n");
}

View File

@ -1,63 +0,0 @@
#include <user_api.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_lora.h>
#include <xs_adapter_manager.h>
extern DoubleLinklistType online_user_head;
void net_lora_gateway(int argc, char *argv[])
{
// 1.New specific agreement (LORA) adapter
static struct AdapterLora lora_adapter;
memset(&lora_adapter, 0, sizeof(lora_adapter));
struct AdapterDone lora_example_done = {
.NetAiitOpen = LoraAdapterOpen,
.NetAiitClose = NULL,
.NetAiitSend = NULL,
.NetAiitReceive = LoraAdapterReceive,
.NetAiitJoin = LoraAdapterJoin,
.NetAiitIoctl = NULL,
};
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
lora_adapter.name = "lora_dev_456"; // Set adapter name
lora_adapter.spi_lora_fd = -1; // Set adapter information
lora_adapter.deve_ui = "xxx";
lora_adapter.app_key = "yyy";
// 2.Register the adapter in the list
LoraAdapterInit();
LoraAdapterRegister((adapter_t)&lora_adapter);
// 3.Find from the list of registered adapters
adapter_t padapter = LoraAdapterFind("lora_dev_456");
if (NONE == padapter)
{
printf("adapter find failed!\n");
return;
}
// 4.Open adapter
if (0 != padapter->done.NetAiitOpen(padapter))
{
printf("adapter open failed!\n");
return;
}
// 5.Join the specified network segment as gateway
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_MASTER, CONNECTION_COMMUNICATION_LORA_NET_ID);
}
static void net_lora_connectedlist(int argc, char *argv[])
{
DoubleLinklistType* pNode;
printf("******** connected users *********\n");
DOUBLE_LINKLIST_FOR_EACH(pNode, &online_user_head)
{
OnlineUser* pUser =CONTAINER_OF(pNode, OnlineUser, link);
printf("%s\n", pUser->user_name);
}
printf("*********************************\n");
}

View File

@ -1,3 +0,0 @@
SRC_FILES := bluetooth_receive_demo.c bluetooth_send_demo.c
# zigbee_send_demo.c zigbee_receive_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,88 +0,0 @@
/*
* 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: bluetooth_receive_demo.c
* @brief: using bluetooth to receive message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_bluetooth.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <user_api.h>
#include <string.h>
static int re_sem;
static int buff_sem;
/*Critical zone protection function for*/
void BluetoothWait(char *rev_buffer)
{
while(1){
if (strlen(rev_buffer)>1){
UserSemaphoreAbandon(re_sem);
break;
}
}
}
/* receive message from another bluetooth device*/
void BluetoothReceiveDemo(int argc, char *argv[])
{
adapter_t padapter = BluetoothAdapterFind("Bluetooth");
if (NONE == padapter){
KPrintf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
KPrintf("adapter open failed!\n");
return;
}
char rev_buffer[NAME_NUM_MAX];
/* Initialize semaphore */
re_sem = UserSemaphoreCreate(0);
/* receive buffer from serial port */
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
BluetoothWait(rev_buffer);
UserSemaphoreObtain(re_sem,-1);
printf("\n");
for (int i=0;i<strlen(rev_buffer);i++)
{
if(rev_buffer[i] != 0Xff)
printf("%c",rev_buffer[i]);
}
printf("\n");
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothReceiveDemo, BluetoothReceiveDemo, bluetooth receive function );
#endif

View File

@ -1,65 +0,0 @@
/*
* 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: bluetooth_send_demo.c
* @brief: using bluetooth to send message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_bluetooth.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <string.h>
#include <user_api.h>
adapter_t padapter;
/* a demo function to send message through command line using bluetooth*/
/* first open bluetooth to start demo*/
void BluetoothOpenDemo()
{
/*Find from the list of registered adapters*/
// adapter_t padapter = BluetoothAdapterFind("Bluetoot");
padapter = BluetoothAdapterFind("Bluetooth");
if (NONE == padapter){
printf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
printf("adapter open failed!\n");
return;
}
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothOpenDemo, BluetoothOpenDemo, bluetooth send function );
#endif
void BluetoothSendDemo(int argc, char *argv[])
{
/*Find from the list of registered adapters*/
bool v = false;
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothSendDemo, BluetoothSendDemo, bluetooth send function );
#endif

View File

@ -1,197 +0,0 @@
/*
* 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 ethernet_demo.c
* @brief Demo for ethernet function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <string.h>
#include <user_api.h>
#include <xs_adapter_manager.h>
#include <xs_adapter_at_ethernet.h>
static bool opened = false;
void OpenEthernetMsg()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
}
void SendEthernetMsg(int argc, char *argv[])
{
char ethernet_msg[128];
if (argc >= 1){
memset(ethernet_msg, 0, 128);
strncpy(ethernet_msg, argv[1], strlen(argv[1]));
printf("SendEthernetMsg(%s).\n", ethernet_msg);
}
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, ethernet_msg, strlen(ethernet_msg), true, 1000, 0, NULL, NULL, NULL);
}
void RecvEthernetMsg()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
while (1){
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, ethernet_recv_msg, 128, 40000, true, NULL))
printf("ethernet_recv_msg (%s)\n", ethernet_recv_msg);
else
printf("ethernet_recv_msg failed .\n");
}
}
void DhcpEthernet()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK != at_adapter->atdone.ATOperateDHCP(at_adapter, 1))
printf("EthernetNetstat failed \n");
}
void PingEthernet()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
struct PingResult result;
char *ip_str = "192.168.250.250";
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK == at_adapter->atdone.ATPing(at_adapter, ip_str, &result))
printf("EthernetPing success (%s)\n", result.ip_addr.ipv4);
else
printf("EthernetPing failed \n");
}
void SetUpEthernet()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
struct PingResult result;
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter))
printf("EthernetSetUp success (%s)\n", result.ip_addr.ipv4);
else
printf("EthernetSetUp failed \n");
}
void NetstatEthernet()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
printf("EthernetNetstat failed \n");
}
void AtTestCmdEthernet(int argc, char *argv[])
{
char cmd[64];
if (argc >= 1){
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, argv[1], strlen(argv[1]));
printf("AT cmd send(%s).\n", cmd);
}
strcat(cmd,"\r");
struct AdapterAT* at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
printf("Waiting for msg...\n");
// Send hfa21 handshake, start cmd mode.
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
UserTaskDelay(100);
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
UserTaskDelay(2500);
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
UserTaskDelay(2500);
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
UserTaskDelay(5000);
}

View File

@ -1,56 +0,0 @@
/*
* 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 nbiot_demo.c
* @brief Demo for NBIoT function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <string.h>
#include <user_api.h>
#include <xs_adapter_at_agent.h>
#include <xs_adapter_manager.h>
#include <xs_adapter_at_nbiot.h>
extern void RegisterAdapterNBIoT(void);
void NbiotEnable(void)
{
struct AdapterAT* at_adapter = ATAdapterFind(NBIOT_ADAPTER_ID);
UserTaskDelay(5000);
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
printf("Waiting for msg...\n");
at_adapter->atdone.ATSocketCreate(at_adapter, 1, SOCKET_TYPE_STREAM, NET_TYPE_AF_INET);
UserTaskDelay(1000);
struct AddressIpv4 addr;
addr.ipv4 = IpTint("115.236.53.226");
at_adapter->atdone.ATSocketConnect(at_adapter, 1, addr, 8989, 0);
int socket_fd = 1;
int count = 0;
while (1) {
UserTaskDelay(1000);
at_adapter->parent.done.NetAiitSend((struct Adapter *)at_adapter, "AB30313233", 5, 0, 0, 0, 0, 0, &socket_fd);
count++;
if (count == 10)
break;
}
}

View File

@ -1,223 +0,0 @@
/*
* 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 wifi_demo.c
* @brief Demo for wifi function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <at_agent.h>
#include <adapter.h>
void SendWiftMsg(int argc, char *argv[])
{
char wifi_msg[128];
int len;
if (argc >= 1) {
memset(wifi_msg, 0, 128);
strncpy(wifi_msg, argv[1], (len = strlen(argv[1])));
printf("SendWiftMsg(%s).\n", wifi_msg);
}
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
AdapterDeviceOpen(adapter);
AdapterDeviceSend(adapter, wifi_msg, len);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), SendWiftMsg, SendWiftMsg, SendWiftMsg);
void RecvWifiMsg()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
AdapterDeviceOpen(adapter);
while (1) {
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
if (EOK == AdapterDeviceRecv(adapter, wifi_recv_msg, 128)) {
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
} else {
printf("wifi_recv_msg failed .\n");
}
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), RecvWifiMsg, RecvWifiMsg, RecvWifiMsg);
void SetUpWifi()
{
char wifi_recv_msg[128];
int baud_rate = BAUD_RATE_57600;
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
if (EOK == AdapterDeviceSetUp(adapter)) {
printf("SetUpWifi success \n");
} else {
printf("SetUpWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetUpWifi, SetUpWifi, SetUpWifi);
void SetDownWifi()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceSetDown(adapter)) {
printf("SetDownWifi success \n");
} else {
printf("SetDownWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetDownWifi, SetDownWifi, SetDownWifi);
void SetAddrWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if(EOK == AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1")){
printf("SetAddrWifi success \n");
} else {
printf("SetAddrWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetAddrWifi, SetAddrWifi, SetAddrWifi);
void PingWifi()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
//www.baidu.com
char *ip_str = "36.152.44.95";
AdapterDeviceOpen(adapter);
if (EOK == AdapterDevicePing(adapter, ip_str)) {
printf("PingWifi success \n");
} else {
printf("PingWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), PingWifi, PingWifi, PingWifi);
void NetstatWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceNetstat(adapter)) {
printf("NetstatWifi success \n");
} else {
printf("NetstatWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), NetstatWifi, NetstatWifi, NetstatWifi);
int ConnectWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
const char *ip = "192.168.66.33";
const char *port = "12345";
enum NetRoleType net_role = CLIENT;
enum IpType ip_type = IPV4;
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceConnect(adapter, net_role, ip, port, ip_type)) {
printf("ConnectWifi success \n");
} else {
printf("ConnectWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), ConnectWifi, ConnectWifi, ConnectWifi);
void AtTestCmdWifi(int argc, char *argv[])
{
char cmd[64];
if (argc >= 1) {
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, argv[1], strlen(argv[1]));
printf("AT cmd send(%s).\n", cmd);
}
strcat(cmd,"\r");
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
// AdapterDeviceOpen(adapter);
printf("Waiting for msg...\n");
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
UserTaskDelay(100);
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "a");
UserTaskDelay(2500);
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,cmd);
UserTaskDelay(2500);
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
UserTaskDelay(5000);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), AtTestCmdWifi, AtTestCmdWifi, AtTestCmdWifi);

View File

@ -1,3 +0,0 @@
SRC_FILES := zigbee_receive_demo.c
# zigbee_send_demo.c zigbee_receive_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,88 +0,0 @@
/*
* 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: zigbee_receive_demo.c
* @brief: using zigbee to receive message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_zigbee.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <user_api.h>
#include <string.h>
static int re_sem;
static int buff_sem;
/*Critical zone protection function for*/
void ZigbeeWait(char *rev_buffer)
{
while(1){
if (strlen(rev_buffer)>1){
UserSemaphoreAbandon(re_sem);
break;
}
}
}
/* receive message from another zigbee device*/
void ZigbeeReceiveDemo(int argc, char *argv[])
{
adapter_t padapter = ZigbeeAdapterFind("zigbee");
if (NONE == padapter){
KPrintf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
KPrintf("adapter open failed!\n");
return;
}
char rev_buffer[NAME_NUM_MAX];
/* Initialize semaphore */
re_sem = UserSemaphoreCreate(0);
/* receive buffer from serial port */
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
ZigbeeWait(rev_buffer);
UserSemaphoreObtain(re_sem,-1);
printf("\n");
for (int i=0;i<strlen(rev_buffer);i++)
{
if(rev_buffer[i] != 0Xff)
printf("%c",rev_buffer[i]);
}
printf("\n");
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeReceiveDemo, ZigbeeReceiveDemo, zigbee receive function );
#endif

View File

@ -1,65 +0,0 @@
/*
* 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: zigbee_send_demo.c
* @brief: using zigbee to send message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_zigbee.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <string.h>
#include <user_api.h>
adapter_t padapter;
/* a demo function to send message through command line using zigbee*/
/* first open zigbee to start demo*/
void ZigbeeOpenDemo()
{
/*Find from the list of registered adapters*/
// adapter_t padapter = ZigbeeAdapterFind("zigbee");
padapter = ZigbeeAdapterFind("zigbee");
if (NONE == padapter){
printf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
printf("adapter open failed!\n");
return;
}
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeOpenDemo, ZigbeeOpenDemo, zigbee send function );
#endif
void ZigbeeSendDemo(int argc, char *argv[])
{
/*Find from the list of registered adapters*/
bool v = false;
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeSendDemo, ZigbeeSendDemo, zigbee send function );
#endif

View File

@ -29,6 +29,10 @@ extern int Hs300xTemperatureInit(void);
extern int Hs300xHumidityInit(void);
extern int Ps5308Pm1_0Init(void);
extern int Zg09Co2Init(void);
extern int As830Ch4Init(void);
extern int Tb600bIaq10IaqInit(void);
extern int Tb600bTvoc10TvocInit(void);
extern int Tb600bWqHcho1osInit(void);
typedef int (*InitFunc)(void);
struct InitDesc
@ -89,6 +93,22 @@ static struct InitDesc sensor_desc[] =
{ "zg09_co2", Zg09Co2Init },
#endif
#ifdef SENSOR_AS830
{ "ch4_as830", As830Ch4Init },
#endif
#ifdef SENSOR_TB600B_IAQ10
{ "iaq_tb600b_iaq10", Tb600bIaq10IaqInit },
#endif
#ifdef SENSOR_TB600B_TVOC10
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
#endif
#ifdef SENSOR_TB600B_WQ_HCHO1OS
{ "tvoc_tb600b_wq_hcho1os", Tb600bWqHcho1osInit },
#endif
{ "NULL", NULL },
};

View File

@ -5,6 +5,46 @@ menu "sensor app"
default n
if APPLICATION_SENSOR
menuconfig APPLICATION_SENSOR_HCHO
bool "Using sensor HCHO apps"
default n
if APPLICATION_SENSOR_HCHO
config APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS
bool "Using sensor TB600B_WQ_HCHO1OS apps"
default n
endif
menuconfig APPLICATION_SENSOR_TVOC
bool "Using sensor TVOC apps"
default n
if APPLICATION_SENSOR_TVOC
config APPLICATION_SENSOR_TVOC_TB600B_TVOC10
bool "Using sensor TB600B_TVOC10 apps"
default n
endif
menuconfig APPLICATION_SENSOR_IAQ
bool "Using sensor IAQ apps"
default n
if APPLICATION_SENSOR_IAQ
config APPLICATION_SENSOR_IAQ_TB600B_IAQ10
bool "Using sensor TB600B_IAQ10 apps"
default n
endif
menuconfig APPLICATION_SENSOR_CH4
bool "Using sensor CH4 apps"
default n
if APPLICATION_SENSOR_CH4
config APPLICATION_SENSOR_CH4_AS830
bool "Using sensor AS830 apps"
default n
endif
menuconfig APPLICATION_SENSOR_CO2
bool "Using sensor CO2 apps"
default n

View File

@ -1,5 +1,21 @@
SRC_FILES :=
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
SRC_FILES += hcho_tb600b_wq_hcho1os.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
SRC_FILES += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
SRC_FILES += iaq_tb600b_iaq10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
SRC_FILES += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
SRC_FILES += co2_zg09.c
endif

View File

@ -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 ch4_as830.c
* @brief CH4 AS830 example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.10
*/
#include <user_api.h>
#include <sensor.h>
/**
* @description: Read a ch4
* @return 0
*/
void Ch4As830(void)
{
struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4);
SensorQuantityOpen(ch4);
printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4));
SensorQuantityClose(ch4);
}

View File

@ -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 hcho_tb600b_wq_hcho1os.c
* @brief hcho example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <user_api.h>
#include <sensor.h>
/**
* @description: Read a hcho
* @return 0
*/
void HchoTb600bHcho1os(void)
{
struct SensorQuantity *hcho = SensorQuantityFind(SENSOR_QUANTITY_TB600B_HCHO, SENSOR_QUANTITY_HCHO);
SensorQuantityOpen(hcho);
int32_t result = 0;
result = SensorQuantityRead(hcho);
printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(hcho);
}

View File

@ -27,9 +27,14 @@
*/
void HumiHs300x(void)
{
int i = 0;
int32 humidity;
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
SensorQuantityOpen(humi);
int32 humidity = SensorQuantityRead(humi);
for (i = 0; i < 100; i ++) {
humidity = SensorQuantityRead(humi);
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
PrivTaskDelay(5000);
}
SensorQuantityClose(humi);
}

View File

@ -0,0 +1,45 @@
/*
* 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 iaq_tb600b_iaq10.c
* @brief iaq10 example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.14
*/
#include <user_api.h>
#include <sensor.h>
// struct iaq_data {
// uint16_t gas;
// uint8_t TH;
// uint8_t TL;
// uint8_t RhH;
// uint8_t RhL;
// };
/**
* @description: Read a iaq
* @return 0
*/
void IaqTb600bIaq10(void)
{
struct SensorQuantity *iaq = SensorQuantityFind(SENSOR_QUANTITY_TB600B_IAQ, SENSOR_QUANTITY_IAQ);
SensorQuantityOpen(iaq);
int32_t result = 0;
result = SensorQuantityRead(iaq);
printf("Gas concentration is : %dppb\n", result);
SensorQuantityClose(iaq);
}

View File

@ -27,12 +27,20 @@
*/
void TempHs300x(void)
{
int i = 0;
int32 temperature;
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
SensorQuantityOpen(temp);
int32 temperature = SensorQuantityRead(temp);
for (i = 0; i < 100; i ++) {
temperature = SensorQuantityRead(temp);
if (temperature > 0)
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
else
printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10);
PrivTaskDelay(5000);
}
SensorQuantityClose(temp);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, TempHs300x, TempHs300x, TempHs300x function);

View File

@ -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 tvoc_tb600b_tvoc10.c
* @brief tvoc10 example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <user_api.h>
#include <sensor.h>
/**
* @description: Read a tvoc
* @return 0
*/
void TvocTb600bTvoc10(void)
{
struct SensorQuantity *tvoc = SensorQuantityFind(SENSOR_QUANTITY_TB600B_TVOC, SENSOR_QUANTITY_TVOC);
SensorQuantityOpen(tvoc);
int32_t result = 0;
result = SensorQuantityRead(tvoc);
printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(tvoc);
}

View File

@ -40,6 +40,10 @@ static void Ec200tPowerSet(void)
{
int pin_fd;
pin_fd = PrivOpen(ADAPTER_EC200T_PIN_DRIVER, O_RDWR);
if (pin_fd < 0) {
printf("open %s error\n", ADAPTER_EC200T_PIN_DRIVER);
return;
}
struct PinParam pin_param;
pin_param.cmd = GPIO_CONFIG_MODE;

View File

@ -1,12 +1,34 @@
menuconfig SUPPORT_CONNECTION_FRAMEWORK
bool "support connection framework"
default n
select TRANSFORM_LAYER_ATTRIUBUTE
if SUPPORT_CONNECTION_FRAMEWORK
config CONNECTION_FRAMEWORK_DEBUG
bool "Using connection framework debug log function"
default y
menuconfig CONNECTION_INDUSTRIAL_ETHERNET
bool "Using industrial ethernet"
default n
if CONNECTION_INDUSTRIAL_ETHERNET
source "$APP_DIR/Framework/connection/industrial_ethernet/Kconfig"
endif
menuconfig CONNECTION_INDUSTRIAL_FIELDBUS
bool "Using industrial fieldbus"
default n
if CONNECTION_INDUSTRIAL_FIELDBUS
source "$APP_DIR/Framework/connection/industrial_fieldbus/Kconfig"
endif
menuconfig CONNECTION_INDUSTRIAL_WLAN
bool "Using industrial wlan"
default n
if CONNECTION_INDUSTRIAL_WLAN
source "$APP_DIR/Framework/connection/industrial_wlan/Kconfig"
endif
menuconfig CONNECTION_ADAPTER_LORA
bool "Using lora adapter device"
default n

View File

@ -1,5 +1,17 @@
SRC_FILES := adapter.c adapter_agent.c
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_ETHERNET),y)
SRC_DIR += industrial_ethernet
endif
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS),y)
SRC_DIR += industrial_fieldbus
endif
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_WLAN),y)
SRC_DIR += industrial_wlan
endif
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
SRC_DIR += lora
endif

View File

@ -1,3 +1,2 @@
SRC_FILES :=wifi_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,2 @@
SRC_FILES :=nbiot_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,2 @@
SRC_FILES := ethernet_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,4 @@
menuconfig SUPPORT_CONTROL_FRAMEWORK
bool "support control framework"
default n
select TRANSFORM_LAYER_ATTRIUBUTE

View File

@ -1,6 +1,7 @@
menuconfig SUPPORT_KNOWING_FRAMEWORK
bool "support knowing framework"
default y
default n
select TRANSFORM_LAYER_ATTRIUBUTE
if SUPPORT_KNOWING_FRAMEWORK
source "$APP_DIR/Framework/knowing/tensorflow-lite/Kconfig"

View File

@ -3,6 +3,7 @@ menu "Security"
menuconfig CRYPTO
bool "using crypto"
default n
select TRANSFORM_LAYER_ATTRIUBUTE
if CRYPTO
menuconfig CRYPTO_SM3
bool "using sm3"

View File

@ -1,8 +1,37 @@
menuconfig SUPPORT_SENSOR_FRAMEWORK
bool "support sensor framework"
default y
default n
select TRANSFORM_LAYER_ATTRIUBUTE
if SUPPORT_SENSOR_FRAMEWORK
menuconfig SENSOR_HCHO
bool "Using HCHO sensor device"
default n
if SENSOR_HCHO
source "$APP_DIR/Framework/sensor/hcho/Kconfig"
endif
menuconfig SENSOR_TVOC
bool "Using TVOC sensor device"
default n
if SENSOR_TVOC
source "$APP_DIR/Framework/sensor/tvoc/Kconfig"
endif
menuconfig SENSOR_IAQ
bool "Using IAQ sensor device"
default n
if SENSOR_IAQ
source "$APP_DIR/Framework/sensor/iaq/Kconfig"
endif
menuconfig SENSOR_CH4
bool "Using Ch4 sensor device"
default n
if SENSOR_CH4
source "$APP_DIR/Framework/sensor/ch4/Kconfig"
endif
menuconfig SENSOR_CO2
bool "Using CO2 sensor device"
default n

View File

@ -1,5 +1,21 @@
SRC_FILES := sensor.c
ifeq ($(CONFIG_SENSOR_HCHO),y)
SRC_DIR += hcho
endif
ifeq ($(CONFIG_SENSOR_TVOC),y)
SRC_DIR += tvoc
endif
ifeq ($(CONFIG_SENSOR_IAQ),y)
SRC_DIR += iaq
endif
ifeq ($(CONFIG_SENSOR_CH4),y)
SRC_DIR += ch4
endif
ifeq ($(CONFIG_SENSOR_CO2),y)
SRC_DIR += co2
endif

View File

@ -0,0 +1,43 @@
config SENSOR_AS830
bool "Using as830"
default n
if SENSOR_AS830
config SENSOR_DEVICE_AS830
string "as830 sensor name"
default "as830_1"
config SENSOR_QUANTITY_AS830_CH4
string "as830 quantity name"
default "ch4_1"
if ADD_XIUOS_FETURES
config SENSOR_AS830_DRIVER_EXTUART
bool "Using extra uart to support as830"
default y
config SENSOR_DEVICE_AS830_DEV
string "as830 device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_AS830_DRIVER_EXTUART
if SENSOR_AS830_DRIVER_EXTUART
config SENSOR_DEVICE_AS830_DEV
string "as830 device extra uart path"
default "/dev/extuart_dev1"
config SENSOR_DEVICE_AS830_DEV_EXT_PORT
int "if AS830 device using extuart, choose port"
default "1"
endif
endif
if ADD_NUTTX_FETURES
endif
if ADD_RTTHREAD_FETURES
endif
endif

View File

@ -0,0 +1,5 @@
ifeq ($(CONFIG_SENSOR_AS830),y)
SRC_DIR += as830
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,3 @@
SRC_FILES := client.c gateway.c
SRC_FILES := as830.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,225 @@
/*
* 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 as830.c
* @brief AS830 CH4 driver base sensor
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.10
*/
#include <sensor.h>
static struct SensorDevice as830;
static struct SensorProductInfo info =
{
SENSOR_ABILITY_CH4,
"xxxxx",
"AS830",
};
/**
* @description: Open AS830 sensor device
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_AS830_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_AS830_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
cfg.serial_stop_bits = STOP_BITS_1;
cfg.serial_buffer_size = 128;
cfg.serial_parity_mode = PARITY_NONE;
cfg.serial_bit_order = 0;
cfg.serial_invert_mode = 0;
#ifdef SENSOR_AS830_DRIVER_EXTUART
cfg.ext_uart_no = SENSOR_DEVICE_AS830_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
#endif
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = &cfg;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8_t tmp = 0;
uint8_t idx = 0;
while (1) {
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
sdev->buffer[idx++] = tmp;
}
if(0xA == tmp){
break;
}
}
return idx;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
NULL,
NULL,
};
/**
* @description: Init AS830 sensor and register
* @return void
*/
static void SensorDeviceAs830Init(void)
{
as830.name = SENSOR_DEVICE_AS830;
as830.info = &info;
as830.done = &done;
SensorDeviceRegister(&as830);
}
/* check data*/
static uint8_t CH4_check(uint8_t *packet)
{
uint8_t i, high, low;
uint8_t checksum = 0;
for( i = 0; i < 10; i++)
{
if(packet[i] == 0x09)
break;
checksum += packet[i];
}
checksum = (unsigned char)(-(signed char)checksum);
high = (checksum & 0xF0) >> 4;
if((high <= 0x0F) && (high >= 0x0A))
high += 0x37;
else if((high <= 0x09) && (high >= 0x00))
high += 0x30;
low = (checksum & 0x0F);
if((low <= 0x0F) && (low >= 0x0A))
low += 0x37;
else if((low <= 0x09) && (low >= 0x00))
low += 0x30;
if((high == packet[i + 1]) && (low == packet[i + 2]))
return 0;
return -1;
}
static struct SensorQuantity as830_ch4;
/**
* @description: Analysis AS830 CH4 result
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32_t QuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -1;
uint32_t result;
uint32_t len = 0;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
len = quant->sdev->done->read(quant->sdev, 7);
if (len == 0)
{
printf("error read data length = 0.\n");
return -1;
}
if(CH4_check(quant->sdev->buffer) == 0)
{
for(int i = 0; i < len; i++)
{
if(quant->sdev->buffer[i] == 0x09)
{
break;
}
result = result *10 + (quant->sdev->buffer[i] - 0x30);
}
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
quant->value.min_value = result;
quant->value.last_value = result;
return result;
}
else
{
printf("This reading is wrong\n");
result = SENSOR_QUANTITY_VALUE_ERROR;
return result;
}
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
{
printf("Please set passive mode.\n");
}
}else{
printf("%s don't have read done.\n", quant->name);
}
return -1;
}
/**
* @description: Init AS830 CH4 quantity and register
* @return 0
*/
int As830Ch4Init(void)
{
SensorDeviceAs830Init();
as830_ch4.name = SENSOR_QUANTITY_AS830_CH4;
as830_ch4.type = SENSOR_QUANTITY_CH4;
as830_ch4.value.decimal_places = 0;
as830_ch4.value.max_std = 1000;
as830_ch4.value.min_std = 350;
as830_ch4.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
as830_ch4.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
as830_ch4.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
as830_ch4.sdev = &as830;
as830_ch4.ReadValue = QuantityRead;
SensorQuantityRegister(&as830_ch4);
return 0;
}

View File

@ -43,6 +43,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_ZG09_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;

View File

@ -0,0 +1,43 @@
config SENSOR_TB600B_WQ_HCHO1OS
bool "Using TB600B WQ_HCHO1OS"
default n
if SENSOR_TB600B_WQ_HCHO1OS
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS
string "tb600b wq_hcho1os sensor name"
default "tb600b_wq_hcho1os_1"
config SENSOR_QUANTITY_TB600B_HCHO
string "tb600b wq_hcho1os quantity name"
default "hcho_1"
if ADD_XIUOS_FETURES
config SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
bool "Using extra uart to support tb600b wq_hcho1os"
default y
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV
string "tb600b wq_hcho1os device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
if SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV
string "tb600b wq_hcho1os device extra uart path"
default "/dev/extuart_dev5"
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV_EXT_PORT
int "if TB600B_WQ_HCHO1OS device using extuart, choose port"
default "5"
endif
endif
if ADD_NUTTX_FETURES
endif
if ADD_RTTHREAD_FETURES
endif
endif

View File

@ -0,0 +1,5 @@
ifeq ($(CONFIG_SENSOR_TB600B_WQ_HCHO1OS),y)
SRC_DIR += tb600b_wq_hcho1os
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := tb600b_wq_hcho1os.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,222 @@
/*
* 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 wq_hcho1os.c
* @brief wq_hcho1os driver base sensor
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <sensor.h>
static struct SensorDevice wq_hcho1os;
static uint8_t ReadInstruction[9];
static struct SensorProductInfo info =
{
SENSOR_ABILITY_HCHO,
"AQS",
"TB600B_WQ_HCHO1OS",
};
/**
* @description: Open TB600B WQ_HCHO1OS sensor device
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
cfg.serial_stop_bits = STOP_BITS_1;
cfg.serial_buffer_size = 128;
cfg.serial_parity_mode = PARITY_NONE;
cfg.serial_bit_order = 0;
cfg.serial_invert_mode = 0;
#ifdef SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
cfg.ext_uart_no = SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
#endif
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = &cfg;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8_t tmp = 0;
uint8_t idx = 0;
/* this instruction will read gas with temperature and humidity,return 9 datas*/
ReadInstruction[0] = 0xFF;
ReadInstruction[1] = 0x01;
ReadInstruction[2] = 0x86;
ReadInstruction[3] = 0x00;
ReadInstruction[4] = 0x00;
ReadInstruction[5] = 0x00;
ReadInstruction[6] = 0x00;
ReadInstruction[7] = 0x00;
ReadInstruction[8] = 0x79;
PrivWrite(sdev->fd, ReadInstruction, 9);
for(idx = 0; idx < 9; idx++)
{
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
sdev->buffer[idx] = tmp;
}
}
return idx;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
{
return PrivWrite(sdev->fd, buf, len);
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
SensorDeviceWrite,
NULL,
};
/**
* @description: Init TB600B WQ_HCHO1OS sensor and register
* @return void
*/
static void SensorDeviceTb600bHcho1osInit(void)
{
wq_hcho1os.name = SENSOR_DEVICE_TB600B_WQ_HCHO1OS;
wq_hcho1os.info = &info;
wq_hcho1os.done = &done;
SensorDeviceRegister(&wq_hcho1os);
}
static struct SensorQuantity wq_hcho1os_hcho;
/* check data*/
static uint8_t getCheckSum(uint8_t *packet)
{
uint8_t i;
uint8_t checksum = 0;
for( i = 1; i < 12; i++)
{
checksum += packet[i];
}
checksum = ~checksum + 1;
return checksum;
}
/**
* @description: Analysis TB600B WQ_HCHO1OS result
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32_t QuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -1;
uint32_t len = 0;
uint8_t checksum = 0;
uint16_t ppb, ugm3;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
len = quant->sdev->done->read(quant->sdev, 9);
if (len == 0)
{
printf("error read data length = 0.\n");
return -1;
}
checksum = getCheckSum(quant->sdev->buffer);
if(checksum == quant->sdev->buffer[8])
{
ugm3 = (uint16_t)quant->sdev->buffer[2] * 256 + (uint16_t)quant->sdev->buffer[3];
ppb = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16_t)quant->sdev->buffer[7];
printf("Formaldehyde concentration is : %dug/m³(%dppb)\n", ugm3, ppb);
return ppb;
}
else
{
printf("This reading is wrong\n");
return SENSOR_QUANTITY_VALUE_ERROR;
}
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
{
printf("Please set passive mode.\n");
}
}else{
printf("%s don't have read done.\n", quant->name);
}
return -1;
}
/**
* @description: Init TB600B WQ_HCHO1OS quantity and register
* @return 0
*/
int Tb600bWqHcho1osInit(void)
{
SensorDeviceTb600bHcho1osInit();
wq_hcho1os_hcho.name = SENSOR_QUANTITY_TB600B_HCHO;
wq_hcho1os_hcho.type = SENSOR_QUANTITY_HCHO;
wq_hcho1os_hcho.value.decimal_places = 0;
wq_hcho1os_hcho.value.max_std = SENSOR_QUANTITY_VALUE_ERROR;
wq_hcho1os_hcho.value.min_std = SENSOR_QUANTITY_VALUE_ERROR;
wq_hcho1os_hcho.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
wq_hcho1os_hcho.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
wq_hcho1os_hcho.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
wq_hcho1os_hcho.sdev = &wq_hcho1os;
wq_hcho1os_hcho.ReadValue = QuantityRead;
SensorQuantityRegister(&wq_hcho1os_hcho);
return 0;
}

View File

@ -16,6 +16,10 @@ config SENSOR_HS300X
config SENSOR_DEVICE_HS300X_DEV
string "HS300x device name"
default "/dev/i2c1_dev0"
config SENSOR_DEVICE_HS300X_I2C_ADDR
hex "HS300x device i2c address"
default 0x44
endif
if ADD_NUTTX_FETURES

View File

@ -32,28 +32,43 @@ static struct SensorProductInfo info =
/**
* @description: Open HS300x sensor device
* @param sdev - sensor device pointer
* @return 1
* @return success : 0 error : -1
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result;
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
return 0;
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV);
return -1;
}
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
ioctl_cfg.args = &i2c_dev_addr;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return success: 1 , failure: -1
* @return success: 0 , failure: -1
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
//send i2c device start signal and address, need to implemente in OS i2c driver
if (PrivWrite(sdev->fd, NULL, 0) != 1)
return -1;
PrivTaskDelay(50);
//Read i2c device data from i2c device address
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
return -1;

View File

@ -0,0 +1,43 @@
config SENSOR_TB600B_IAQ10
bool "Using TB600B IAQ10"
default n
if SENSOR_TB600B_IAQ10
config SENSOR_DEVICE_TB600B_IAQ10
string "tb600b iaq10 sensor name"
default "tb600b_iaq10_1"
config SENSOR_QUANTITY_TB600B_IAQ
string "tb600b iaq10 quantity name"
default "iaq_1"
if ADD_XIUOS_FETURES
config SENSOR_TB600B_IAQ10_DRIVER_EXTUART
bool "Using extra uart to support tb600b iaq10"
default y
config SENSOR_DEVICE_TB600B_IAQ10_DEV
string "tb600b iaq10 device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_TB600B_IAQ10_DRIVER_EXTUART
if SENSOR_TB600B_IAQ10_DRIVER_EXTUART
config SENSOR_DEVICE_TB600B_IAQ10_DEV
string "tb600b iaq10 device extra uart path"
default "/dev/extuart_dev5"
config SENSOR_DEVICE_TB600B_IAQ10_DEV_EXT_PORT
int "if TB600B_IAQ10 device using extuart, choose port"
default "5"
endif
endif
if ADD_NUTTX_FETURES
endif
if ADD_RTTHREAD_FETURES
endif
endif

View File

@ -0,0 +1,5 @@
ifeq ($(CONFIG_SENSOR_TB600B_IAQ10),y)
SRC_DIR += tb600b_iaq10
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := tb600b_iaq10.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,235 @@
/*
* 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 tb600b_iaq10.c
* @brief tb600b_iaq10 driver base sensor
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.14
*/
#include <sensor.h>
static struct SensorDevice tb600b_iaq10;
static uint8_t ReadInstruction[9];
struct iaq_data {
uint16_t gas;
uint8_t TH;
uint8_t TL;
uint8_t RhH;
uint8_t RhL;
};
static struct SensorProductInfo info =
{
SENSOR_ABILITY_IAQ,
"AQS",
"TB600B_IAQ10",
};
/**
* @description: Open tb600b_iaq10 sensor device
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_TB600B_IAQ10_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_TB600B_IAQ10_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
cfg.serial_stop_bits = STOP_BITS_1;
cfg.serial_buffer_size = 128;
cfg.serial_parity_mode = PARITY_NONE;
cfg.serial_bit_order = 0;
cfg.serial_invert_mode = 0;
#ifdef SENSOR_TB600B_IAQ10_DRIVER_EXTUART
cfg.ext_uart_no = SENSOR_DEVICE_TB600B_IAQ10_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
#endif
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = &cfg;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8_t tmp = 0;
uint8_t idx = 0;
int32_t ret = 0;
/* this instruction will read gas with temperature and humidity,return 13 datas*/
ReadInstruction[0] = 0xFF;
ReadInstruction[1] = 0x01;
ReadInstruction[2] = 0x87;
ReadInstruction[3] = 0x00;
ReadInstruction[4] = 0x00;
ReadInstruction[5] = 0x00;
ReadInstruction[6] = 0x00;
ReadInstruction[7] = 0x00;
ReadInstruction[8] = 0x78;
PrivWrite(sdev->fd, ReadInstruction, 9);
for(idx = 0; idx < 13; idx++)
{
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
sdev->buffer[idx] = tmp;
}
}
return idx;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
{
return PrivWrite(sdev->fd, buf, len);
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
SensorDeviceWrite,
NULL,
};
/**
* @description: Init tb600b_iaq10 sensor and register
* @return void
*/
static void SensorDeviceTb600bIaq10Init(void)
{
tb600b_iaq10.name = SENSOR_DEVICE_TB600B_IAQ10;
tb600b_iaq10.info = &info;
tb600b_iaq10.done = &done;
SensorDeviceRegister(&tb600b_iaq10);
}
static struct SensorQuantity tb600b_iaq10_iaq;
/* check data*/
static uint8_t getCheckSum(uint8_t *packet)
{
uint8_t i;
uint8_t checksum = 0;
for( i = 1; i < 12; i++)
{
checksum += packet[i];
}
checksum = ~checksum + 1;
return checksum;
}
/**
* @description: Analysis tb600b_iaq10 result
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32_t QuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -1;
uint32_t len = 0;
uint8_t checksum = 0;
uint8_t TH, TL, RhH, RhL;
uint16_t gas;
struct iaq_data result;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
len = quant->sdev->done->read(quant->sdev, 13);
if (len == 0)
{
printf("error read data length = 0.\n");
return -1;
}
checksum = getCheckSum(quant->sdev->buffer);
if(checksum == quant->sdev->buffer[12])
{
result.gas = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16_t)quant->sdev->buffer[7];
result.TH = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))/100;
result.TL = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))%100;
result.RhH = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))/100;
result.RhL = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))%100;
printf("Gas concentration is : %dppb\nThe temperature is : %d.%d℃\nThe humidity is : %d.%drh%%\n", result.gas, result.TH, result.TL, result.RhH, result.RhL);
return result.gas;
}
else
{
printf("This reading is wrong\n");
return SENSOR_QUANTITY_VALUE_ERROR;
}
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
{
printf("Please set passive mode.\n");
}
}else{
printf("%s don't have read done.\n", quant->name);
}
return -1;
}
/**
* @description: Init tb600b_iaq10 quantity and register
* @return 0
*/
int Tb600bIaq10IaqInit(void)
{
SensorDeviceTb600bIaq10Init();
tb600b_iaq10_iaq.name = SENSOR_QUANTITY_TB600B_IAQ;
tb600b_iaq10_iaq.type = SENSOR_QUANTITY_IAQ;
tb600b_iaq10_iaq.value.decimal_places = 0;
tb600b_iaq10_iaq.value.max_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_iaq10_iaq.value.min_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_iaq10_iaq.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_iaq10_iaq.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_iaq10_iaq.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_iaq10_iaq.sdev = &tb600b_iaq10;
tb600b_iaq10_iaq.ReadValue = QuantityRead;
SensorQuantityRegister(&tb600b_iaq10_iaq);
return 0;
}

View File

@ -58,6 +58,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
PrivMutexCreate(&buff_lock, 0);
sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_PS5308_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;

View File

@ -51,6 +51,10 @@ extern "C" {
#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO))
#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM))
#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE))
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ))
#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC))
#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO))
struct SensorProductInfo {
uint32_t ability; /* Bitwise OR of sensor ability */
@ -89,6 +93,9 @@ enum SensorQuantityType {
SENSOR_QUANTITY_CO,
SENSOR_QUANTITY_PM,
SENSOR_QUANTITY_VOICE,
SENSOR_QUANTITY_CH4,
SENSOR_QUANTITY_IAQ,
SENSOR_QUANTITY_TVOC,
/* ...... */
SENSOR_QUANTITY_END,
};

View File

@ -16,6 +16,10 @@ config SENSOR_HS300X
config SENSOR_DEVICE_HS300X_DEV
string "HS300x device name"
default "/dev/i2c1_dev0"
config SENSOR_DEVICE_HS300X_I2C_ADDR
hex "HS300x device i2c address"
default 0x44
endif
if ADD_NUTTX_FETURES

View File

@ -32,28 +32,42 @@ static struct SensorProductInfo info =
/**
* @description: Open HS300x sensor device
* @param sdev - sensor device pointer
* @return 1
* @return success : 0 error : -1
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
int result;
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
return 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV);
return -1;
}
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
ioctl_cfg.args = &i2c_dev_addr;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return success: 1 , failure: -1
* @return success: 0 , failure: -1
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
//send i2c device start signal and address, need to implemente in OS i2c driver
if (PrivWrite(sdev->fd, NULL, 0) != 1)
return -1;
PrivTaskDelay(50);
//Read i2c device data from i2c device address
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
return -1;
@ -101,6 +115,7 @@ static int32_t ReadTemperature(struct SensorQuantity *quant)
if (quant->sdev->done->read != NULL) {
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
quant->sdev->done->read(quant->sdev, 4);
PrivTaskDelay(50);
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
result = ((quant->sdev->buffer[2] << 8 | quant->sdev->buffer[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0;

View File

@ -0,0 +1,43 @@
config SENSOR_TB600B_TVOC10
bool "Using TB600B TVOC10"
default n
if SENSOR_TB600B_TVOC10
config SENSOR_DEVICE_TB600B_TVOC10
string "tb600b tvoc10 sensor name"
default "tb600b_tvoc10_1"
config SENSOR_QUANTITY_TB600B_TVOC
string "tb600b tvoc10 quantity name"
default "tvoc_1"
if ADD_XIUOS_FETURES
config SENSOR_TB600B_TVOC10_DRIVER_EXTUART
bool "Using extra uart to support tb600b tvoc10"
default y
config SENSOR_DEVICE_TB600B_TVOC10_DEV
string "tb600b tvoc10 device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_TB600B_TVOC10_DRIVER_EXTUART
if SENSOR_TB600B_TVOC10_DRIVER_EXTUART
config SENSOR_DEVICE_TB600B_TVOC10_DEV
string "tb600b tvoc10 device extra uart path"
default "/dev/extuart_dev6"
config SENSOR_DEVICE_TB600B_TVOC10_DEV_EXT_PORT
int "if TB600B_TVOC10 device using extuart, choose port"
default "6"
endif
endif
if ADD_NUTTX_FETURES
endif
if ADD_RTTHREAD_FETURES
endif
endif

View File

@ -0,0 +1,5 @@
ifeq ($(CONFIG_SENSOR_TB600B_TVOC10),y)
SRC_DIR += tb600b_tvoc10
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := tb600b_tvoc10.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,227 @@
/*
* 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 tb600b_tvoc10.c
* @brief tb600b_tvoc10 driver base sensor
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <sensor.h>
static struct SensorDevice tb600b_tvoc10;
static uint8_t ReadInstruction[9];
static struct SensorProductInfo info =
{
SENSOR_ABILITY_TVOC,
"AQS",
"TB600B_TVOC10",
};
/**
* @description: Open TB600B TVOC10 sensor device
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_TB600B_TVOC10_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_TB600B_TVOC10_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
cfg.serial_stop_bits = STOP_BITS_1;
cfg.serial_buffer_size = 128;
cfg.serial_parity_mode = PARITY_NONE;
cfg.serial_bit_order = 0;
cfg.serial_invert_mode = 0;
#ifdef SENSOR_TB600B_TVOC10_DRIVER_EXTUART
cfg.ext_uart_no = SENSOR_DEVICE_TB600B_TVOC10_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
#endif
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = &cfg;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
return result;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8_t tmp = 0;
uint8_t idx = 0;
/* this instruction will read gas with temperature and humidity,return 13 datas*/
ReadInstruction[0] = 0xFF;
ReadInstruction[1] = 0x01;
ReadInstruction[2] = 0x87;
ReadInstruction[3] = 0x00;
ReadInstruction[4] = 0x00;
ReadInstruction[5] = 0x00;
ReadInstruction[6] = 0x00;
ReadInstruction[7] = 0x00;
ReadInstruction[8] = 0x78;
PrivWrite(sdev->fd, ReadInstruction, 9);
for(idx = 0; idx < 13; idx++)
{
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
sdev->buffer[idx] = tmp;
}
}
return idx;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return get data length
*/
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
{
return PrivWrite(sdev->fd, buf, len);
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
SensorDeviceWrite,
NULL,
};
/**
* @description: Init TB600B TVOC10 sensor and register
* @return void
*/
static void SensorDeviceTb600bTvoc10Init(void)
{
tb600b_tvoc10.name = SENSOR_DEVICE_TB600B_TVOC10;
tb600b_tvoc10.info = &info;
tb600b_tvoc10.done = &done;
SensorDeviceRegister(&tb600b_tvoc10);
}
static struct SensorQuantity tb600b_tvoc10_tvoc;
/* check data*/
static uint8_t getCheckSum(uint8_t *packet)
{
uint8_t i;
uint8_t checksum = 0;
for( i = 1; i < 12; i++)
{
checksum += packet[i];
}
checksum = ~checksum + 1;
return checksum;
}
/**
* @description: Analysis TB600B TVOC10 result
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32_t QuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -1;
uint32_t len = 0;
uint8_t checksum = 0;
uint8_t TH, TL, RhH, RhL;
uint16_t ppb, ugm3;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
len = quant->sdev->done->read(quant->sdev, 13);
if (len == 0)
{
printf("error read data length = 0.\n");
return -1;
}
checksum = getCheckSum(quant->sdev->buffer);
if(checksum == quant->sdev->buffer[12])
{
ugm3 = (uint16_t)quant->sdev->buffer[2] * 256 + (uint16_t)quant->sdev->buffer[3];
ppb = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16_t)quant->sdev->buffer[7];
TH = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))/100;
TL = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))%100;
RhH = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))/100;
RhL = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))%100;
printf("tvoc concentration is : %dug/m³(%dppb)\nThe temperature is : %d.%d℃\nThe humidity is : %d.%drh%%\n", ugm3, ppb, TH, TL, RhH, RhL);
return ppb;
}
else
{
printf("This reading is wrong\n");
return SENSOR_QUANTITY_VALUE_ERROR;
}
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
{
printf("Please set passive mode.\n");
}
}else{
printf("%s don't have read done.\n", quant->name);
}
return -1;
}
/**
* @description: Init TB600B TVOC10 quantity and register
* @return 0
*/
int Tb600bTvoc10TvocInit(void)
{
SensorDeviceTb600bTvoc10Init();
tb600b_tvoc10_tvoc.name = SENSOR_QUANTITY_TB600B_TVOC;
tb600b_tvoc10_tvoc.type = SENSOR_QUANTITY_TVOC;
tb600b_tvoc10_tvoc.value.decimal_places = 0;
tb600b_tvoc10_tvoc.value.max_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.min_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.sdev = &tb600b_tvoc10;
tb600b_tvoc10_tvoc.ReadValue = QuantityRead;
SensorQuantityRegister(&tb600b_tvoc10_tvoc);
return 0;
}

View File

@ -59,6 +59,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
PrivMutexCreate(&buff_lock, 0);
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_D124_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;

View File

@ -151,6 +151,9 @@ int PrivIoctl(int fd, int cmd, void *args)
case PIN_TYPE:
ret = PrivPinIoctl(fd, cmd, ioctl_cfg->args);
break;
case I2C_TYPE:
ret = ioctl(fd, cmd, ioctl_cfg->args);
break;
default:
break;
}

View File

@ -5,7 +5,7 @@ MAKEFLAGS += --no-print-directory
.PHONY:COMPILE_APP COMPILE_KERNEL
support :=kd233 stm32f407-st-discovery maix-go stm32f407zgt6 aiit-riscv64-board aiit-arm32-board hifive1-rev-B hifive1-emulator k210-emulator cortex-m3-emulator cortex-m4-emulator ok1052-c gapuino stm32f103-nano gd32vf103_rvstar
support :=kd233 stm32f407-st-discovery maix-go stm32f407zgt6 aiit-riscv64-board aiit-arm32-board hifive1-rev-B hifive1-emulator k210-emulator cortex-m3-emulator cortex-m4-emulator ok1052-c gapuino stm32f103-nano gd32vf103_rvstar cortex-m0-emulator
SRC_DIR:=
export BOARD ?=kd233

View File

@ -1,24 +1,29 @@
#公共部分
SRC_DIR := shared
# The following three platforms support compatiable instructions.
ifeq ($(CONFIG_BOARD_CORTEX_M3_EVB),y)
SRC_DIR := shared
SRC_DIR += cortex-m3
endif
ifeq ($(CONFIG_BOARD_STM32F103_NANO),y)
SRC_DIR := shared
SRC_DIR +=cortex-m3
endif
ifeq ($(CONFIG_BOARD_STM32F407_EVB),y)
SRC_DIR +=cortex-m4
endif
ifeq ($(CONFIG_BOARD_CORTEX_M4_EVB),y)
SRC_DIR := shared
SRC_DIR += cortex-m4
endif
ifeq ($(CONFIG_BOARD_CORTEX_M7_EVB),y)
SRC_DIR := shared
SRC_DIR += cortex-m7
endif
# cortex-m0 is ARMv6-m
ifeq ($(CONFIG_BOARD_CORTEX_M0_EVB),y)
SRC_DIR += cortex-m0
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := boot.c interrupt.c interrupt_vector.S pendsv.S prepare_ahwstack.c arm32_switch.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,28 @@
/*
* 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.
*/
#ifndef ARCH_INTERRUPT_H__
#define ARCH_INTERRUPT_H__
#include <xs_base.h>
#define ARCH_MAX_IRQ_NUM (48)
#define ARCH_IRQ_NUM_OFFSET 0
#define SYSTICK_IRQN 15
#define UART1_IRQn 18
int32 ArchEnableHwIrq(uint32 irq_num);
int32 ArchDisableHwIrq(uint32 irq_num);
#endif

View File

@ -0,0 +1,241 @@
/*
* 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.
*/
#include <xs_base.h>
#include <xs_ktask.h>
#define SCB_VTOR "0xE000ED08"
#define NVIC_INT_CTRL "0xE000ED04"
#define NVIC_SYSPRI2 "0xE000ED20"
#define NVIC_PENDSV_PRI "0x00FF0000"
#define NVIC_PENDSVSET "0x10000000"
/* We replaced instructions that were not supported in thumb mode. */
void __attribute__((naked)) HwInterruptcontextSwitch(x_ubase from, x_ubase to, struct TaskDescriptor *to_task, void *context)
{
asm volatile ("PUSH {R4}");
asm volatile ("PUSH {R5}");
asm volatile ("LDR r4, =KtaskSwitchInterruptFlag");
asm volatile ("LDR r5, [r4]");
asm volatile ("CMP r5, #1");
asm volatile ("POP {R5}");
asm volatile ("POP {R4}");
asm volatile ("BEQ Arm32SwitchReswitch");
asm volatile ("PUSH {R4}");
asm volatile ("PUSH {R5}");
asm volatile ("LDR r4, =KtaskSwitchInterruptFlag");
asm volatile ("MOV r5, #1");
asm volatile ("STR r5, [r4]");
asm volatile ("LDR r4, =InterruptFromKtask");
asm volatile ("STR r0, [r4]");
asm volatile ("POP {R5}");
asm volatile ("POP {R4}");
asm volatile ("B Arm32SwitchReswitch");
}
void __attribute__((naked)) Arm32SwitchReswitch()
{
asm volatile ("PUSH {R4}");
asm volatile ("LDR r4, =InterruptToKtask");
asm volatile ("STR r1, [r4]");
asm volatile ("LDR r4, =InterruptToKtaskDescriptor");
asm volatile ("STR r2, [r4]");
asm volatile ("LDR r0, =" NVIC_INT_CTRL);
asm volatile ("LDR r1, =" NVIC_PENDSVSET);
asm volatile ("STR r1, [r0]");
asm volatile ("POP {R4}");
asm volatile ("BX LR");
}
void __attribute__((naked)) SwitchKtaskContext(x_ubase from, x_ubase to, struct TaskDescriptor *to_task)
{
asm volatile("B HwInterruptcontextSwitch");
}
void SwitchKtaskContextTo(x_ubase to, struct TaskDescriptor *to_task)
{
asm volatile ("LDR r2, =InterruptToKtask");
asm volatile ("STR r0, [r2]");
asm volatile ("LDR r2, =InterruptToKtaskDescriptor");
asm volatile ("STR r1, [r2]");
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
asm volatile ("MRS r2, CONTROL");
asm volatile ("BIC r2, #0x04");
asm volatile ("MSR CONTROL, r2");
#endif
asm volatile ("LDR r1, =InterruptFromKtask");
asm volatile ("MOV r0, #0x0");
asm volatile ("STR r0, [r1]");
asm volatile ("LDR r1, =KtaskSwitchInterruptFlag");
asm volatile ("MOV r0, #1");
asm volatile ("STR r0, [r1]");
asm volatile ("LDR r0, =" NVIC_SYSPRI2);
asm volatile ("LDR r1, =" NVIC_PENDSV_PRI);
// asm volatile ("LDR.W r2, [r0,#0x00]");
asm volatile ("LDR r2, [r0,#0x00]");
asm volatile ("ORR r1,r1,r2");
asm volatile ("STR r1, [r0]");
asm volatile ("LDR r0, =" NVIC_INT_CTRL);
asm volatile ("LDR r1, =" NVIC_PENDSVSET);
asm volatile ("STR r1, [r0]");
asm volatile ("LDR r0, =" SCB_VTOR);
asm volatile ("LDR r0, [r0]");
asm volatile ("LDR r0, [r0]");
asm volatile ("NOP");
asm volatile ("MSR msp, r0");
asm volatile ("CPSIE F");
asm volatile ("CPSIE I");
asm volatile ("BX lr");
}
void __attribute__((naked)) HardFaultHandler()
{
asm volatile ("MRS r0, msp");
// asm volatile ("TST lr, #0x04");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x04");
asm volatile ("TST r1, r2");
asm volatile ("BEQ Arm32SwitchGetSpDone");
asm volatile ("MRS r0, psp");
asm volatile ("B Arm32SwitchGetSpDone");
}
void __attribute__((naked)) Arm32SwitchGetSpDone()
{
asm volatile ("MRS r3, primask");
// asm volatile ("STMFD r0!, {r3 - r11}");
asm volatile ("SUB r0, r0, #0x24");
asm volatile ("STMIA r0!, {r3 - r7}");
asm volatile ("MOV r3, r8");
asm volatile ("MOV r4, r9");
asm volatile ("MOV r5, r10");
asm volatile ("MOV r6, r11");
asm volatile ("STMIA r0!, {r3 - r6}");
asm volatile ("SUB r0, r0, #0x24");
// asm volatile ("STMFD r0!, {lr}");
asm volatile ("SUB r0, r0, #0x4");
asm volatile ("MOV r0, lr");
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
asm volatile ("MOV r4, #0x00");
// asm volatile ("TST lr, #0x10");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x10");
asm volatile ("TST r1, r2");
asm volatile ("MOVEQ r4, #0x01");
asm volatile ("STMFD r0!, {r4}");
#endif
// asm volatile ("TST lr, #0x04");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x04");
asm volatile ("TST r1, r2");
asm volatile ("BEQ Arm32SwitchUpdateMsp");
asm volatile ("MSR psp, r0");
asm volatile ("B Arm32SwitchUpdateDone");
asm volatile ("B Arm32SwitchUpdateMsp");
}
void __attribute__((naked)) Arm32SwitchUpdateMsp()
{
asm volatile ("MSR msp, r0");
asm volatile ("B Arm32SwitchUpdateDone");
}
void __attribute__((naked)) Arm32SwitchUpdateDone()
{
asm volatile ("PUSH {LR}");
asm volatile ("BL HwHardFaultException");
// asm volatile ("POP {LR}");
asm volatile ("POP {R1}");
asm volatile ("MOV lr, r1");
// asm volatile ("ORR lr, lr, #0x04");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x04");
asm volatile ("ORR r1, r2");
asm volatile ("MOV lr, r1");
asm volatile ("BX lr");
}
void __attribute__((naked)) MemFaultHandler()
{
asm volatile ("MRS r0, msp");
// asm volatile ("TST lr, #0x04");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x04");
asm volatile ("TST r1, r2");
asm volatile ("BEQ Arm32Switch1");
asm volatile ("MRS r0, psp");
asm volatile ("B Arm32Switch1");
}
void __attribute__((naked)) Arm32Switch1()
{
asm volatile ("MRS r3, primask");
// asm volatile ("STMFD r0!, {r3 - r11}");
asm volatile ("SUB r0, r0, #0x24");
asm volatile ("STMIA r0!, {r3 - r7}");
asm volatile ("MOV r3, r8");
asm volatile ("MOV r4, r9");
asm volatile ("MOV r5, r10");
asm volatile ("MOV r6, r11");
asm volatile ("STMIA r0!, {r3 - r6}");
asm volatile ("SUB r0, r0, #0x24");
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
asm volatile ("MOV r4, #0x00");
// asm volatile ("TST lr, #0x10");
asm volatile ("MOV r1, lr");
asm volatile ("MOV r2, #0x10");
asm volatile ("TST r1, r2");
asm volatile ("MOV lr, r1");
asm volatile ("MOVEQ r4, #0x01");
asm volatile ("STMFD r0!, {r4}");
#endif
// asm volatile ("STMFD r0!, {lr}");
asm volatile ("SUB r0, r0, #0x4");
asm volatile ("MOV r0, lr");
asm volatile ("PUSH {LR}");
asm volatile ("BL MemFaultHandle");
// asm volatile ("POP {LR}");
asm volatile ("POP {R5}");
asm volatile ("MOV lr, r5");
// asm volatile ("ORR lr, lr, #0x04");
asm volatile ("MOV r5, lr");
asm volatile ("MOV r6, #0x04");
asm volatile ("ORR r5, r6");
asm volatile ("MOV lr, r5");
asm volatile ("BX lr");
}

View File

@ -0,0 +1,75 @@
//*****************************************************************************
//
// startup_gcc.c - Startup code for use with GNU tools.
//
// Copyright (c) 2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 10636 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
/**
* @file boot.c
* @brief derived from Stellaris Firmware Development Package
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-13
*/
/*************************************************
File name: boot.c
Description: Reset and init function
Others:
History:
1. Date: 2021-05-13
Author: AIIT XUOS Lab
Modification:
1. take startup_gcc.c from revision 10636 of the Stellaris Firmware Development Package for XiUOS
*************************************************/
extern unsigned _sdata[], _edata[],
_sbss[], _ebss[], _etext[], _sidata[];
extern int entry(void);
void
Reset_Handler(void)
{
unsigned *p, *q;
p = _sdata; q = _sidata;
while (p < _edata) *p++ = *q++;
p = _sbss;
while (p < _ebss) *p++ = 0;
entry();
}

View File

@ -0,0 +1,83 @@
/*
* 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 interrupt.c
* @brief support arm cortex-m4 interrupt function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-29
*/
#include <xs_base.h>
#include <xs_isr.h>
x_base __attribute__((naked)) DisableLocalInterrupt()
{
asm volatile ("MRS r0, PRIMASK");
asm volatile ("CPSID I");
asm volatile ("BX LR ");
}
void __attribute__((naked)) EnableLocalInterrupt(x_base level)
{
asm volatile ("MSR PRIMASK, r0");
asm volatile ("BX LR");
}
int32 ArchEnableHwIrq(uint32 irq_num)
{
return EOK;
}
int32 ArchDisableHwIrq(uint32 irq_num)
{
return EOK;
}
extern void KTaskOsAssignAfterIrq(void *context);
void IsrEntry()
{
uint32 ipsr;
__asm__ volatile("MRS %0, IPSR" : "=r"(ipsr));
isrManager.done->incCounter();
isrManager.done->handleIrq(ipsr);
KTaskOsAssignAfterIrq(NONE);
isrManager.done->decCounter();
}
void UsageFault_Handler(int irqn, void *arg)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
void BusFault_Handler(int irqn, void *arg)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
void NMI_Handler(int irqn, void *arg)
{
while (1)
{
}
}

View File

@ -0,0 +1,122 @@
//*****************************************************************************
//
// startup_gcc.c - Startup code for use with GNU tools.
//
// Copyright (c) 2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 10636 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
/**
* @file interrupt_vector.S
* @brief derived from Stellaris Firmware Development Package
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-13
*/
/*************************************************
File name: interrupt_vector.S
Description: vector table for a Cortex M3
Others:
History:
1. Date: 2021-05-13
Author: AIIT XUOS Lab
Modification:
1. take startup_gcc.c from revision 10636 of the Stellaris Firmware Development Package for XiUOS
*************************************************/
//*****************************************************************************
//
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x0000.0000.
//
//*****************************************************************************
.globl InterruptVectors
/******************************************************************************
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type InterruptVectors, %object
.size InterruptVectors, .-InterruptVectors
InterruptVectors:
.word _sp
.word Reset_Handler
.word NMI_Handler // NMI_Handler
.word HardFaultHandler
.word MemFaultHandler // MemManage_Handler
.word BusFault_Handler // BusFault_Handler
.word UsageFault_Handler // UsageFault_Handler
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry // SVC_Handler
.word IsrEntry // DebugMon_Handler
.word IsrEntry
.word PendSV_Handler // PendSV_Handler
.word IsrEntry // systick
.word IsrEntry
.word IsrEntry
.word IsrEntry // UART
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry
.word IsrEntry

View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-10-11 Bernard first version
* 2012-01-01 aozima support context switch load/store FPU register.
* 2013-06-18 aozima add restore MSP feature.
* 2013-06-23 aozima support lazy stack optimized.
* 2018-07-24 aozima enhancement hard fault exception handler.
*/
/*************************************************
File name: pendsv.S
Description: PendSV interrupt handler
Others: take RT-Thread v4.0.2/libcpu/arm/cortex-m4/context_gcc.S for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
*************************************************/
#include <xsconfig.h>
.cpu cortex-m0
.syntax unified
.thumb
.text
.equ SCB_VTOR, 0xE000ED08
.equ NVIC_INT_CTRL, 0xE000ED04
.equ NVIC_SYSPRI2, 0xE000ED20
.equ NVIC_PENDSV_PRI, 0x00FF0000
.equ NVIC_PENDSVSET, 0x10000000
.globl PendSV_Handler
.type PendSV_Handler, %function
PendSV_Handler:
MRS r3, PRIMASK
CPSID I
LDR r0, =KtaskSwitchInterruptFlag
LDR r1, [r0]
/*CBZ r1, switch_to_task*/
CMP r1, #0
BEQ pendsv_exit
MOVS r1, #0x00
STR r1, [r0]
LDR r0, =InterruptFromKtask
LDR r1, [r0]
/*CBZ r1, switch_to_task*/
CMP r1, #0
BEQ switch_to_task
MRS r1, psp
/*STMFD r1!, {r3 - r11}*/
SUBS r1, #0x24
STMIA r1!, {r3 - r7}
MOV r3, r8
MOV r4, r9
MOV r5, r10
MOV r6, r11
STMIA r1!, {r3 - r6}
SUBS r1, #0x24
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
MOV r4, #0x00
TST lr, #0x10
MOVEQ r4, #0x01
/*STMFD r1!, {r4}*/
SUBS r1, #0x4
STMIA r1!, {r4}
SUBS r1, #0x4
#endif
LDR r0, [r0]
STR r1, [r0]
switch_to_task:
PUSH {lr}
BL UpdateRunningTask
POP {r0}
MOV lr, r0
#ifdef TASK_ISOLATION
PUSH {lr}
BL GetTaskPrivilege
/*POP {lr}*/
POP {r0}
MOV lr, r0
#endif
LDR r1, =InterruptToKtask
LDR r1, [r1]
LDR r1, [r1]
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
LDMFD r1!, {r2}
#endif
/*LDMFD r1!, {r3 - r11}*/
ADDS r1, #0x14
LDMFD r1!, {r3 - r6}
MOV r8, r3
MOV r9, r4
MOV r10, r5
MOV r11, r6
SUBS r1, #0x24
LDMFD r1!, {r3 - r7}
ADDS r1, #0x10
MSR psp, r1
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
/*ORR lr, lr, #0x10*/
MOV r2, lr
MOVS r3, #0x10
ORRS r2, r3
MOV lr, r2
CMP r2, #0
BICNE lr, lr, #0x10
#endif
MRS r2, control
#ifdef TASK_ISOLATION
CMP r0, #1
BEQ unprivilege
privilege:
BIC r2, r2, #0x01
B exit
unprivilege:
/*ORR r2, r2, #0x01*/
MOVS r1, #0x01
ORRS r2, r1
#else
/*BIC r2, r2, #0x01*/
MOVS r0, #0x01
BICS r2, r0
#endif
exit:
MSR control, r2
pendsv_exit:
/*ORR lr, lr, #0x04*/
MOV r0, lr
MOVS r1, #0x04
ORRS r0, r1
MOV lr, r0
MSR PRIMASK, r3
BX lr

View File

@ -0,0 +1,411 @@
/*
* 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.
*/
#include <xs_base.h>
#include <xs_ktask.h>
#include <xs_assign.h>
#include "svc_handle.h"
#include <board.h>
#include <shell.h>
#if (defined ( __GNUC__ ) && defined ( __VFP_FP__ ) && !defined(__SOFTFP__))
#define USE_FPU 1
#else
#define USE_FPU 0
#endif
uint32 InterruptFromKtask;
uint32 InterruptToKtask;
uint32 KtaskSwitchInterruptFlag;
uint32 InterruptToKtaskDescriptor;
#define RunningKTask Assign.os_running_task
static x_err_t (*ExceptionHook)(void *context) = NONE;
struct ExceptionStackRegister
{
uint32 r0;
uint32 r1;
uint32 r2;
uint32 r3;
uint32 r12;
uint32 lr;
uint32 pc;
uint32 psr;
};
struct StackRegisterContent
{
#if defined ( __VFP_FP__ ) && !defined(__SOFTFP__)
uint32 flag;
#endif
uint32 primask;
uint32 r4;
uint32 r5;
uint32 r6;
uint32 r7;
uint32 r8;
uint32 r9;
uint32 r10;
uint32 r11;
// uint32 exc_ret;
struct ExceptionStackRegister ExErrorStackContex;
};
struct ExceptionStackFrameFpu
{
uint32 r0;
uint32 r1;
uint32 r2;
uint32 r3;
uint32 r12;
uint32 lr;
uint32 pc;
uint32 psr;
#if USE_FPU
uint32 S0;
uint32 S1;
uint32 S2;
uint32 S3;
uint32 S4;
uint32 S5;
uint32 S6;
uint32 S7;
uint32 S8;
uint32 S9;
uint32 S10;
uint32 S11;
uint32 S12;
uint32 S13;
uint32 S14;
uint32 S15;
uint32 FPSCR;
uint32 NO_NAME;
#endif
};
struct StackFrameFpu
{
uint32 flag;
uint32 r4;
uint32 r5;
uint32 r6;
uint32 r7;
uint32 r8;
uint32 r9;
uint32 r10;
uint32 r11;
#if USE_FPU
uint32 s16;
uint32 s17;
uint32 s18;
uint32 s19;
uint32 s20;
uint32 s21;
uint32 s22;
uint32 s23;
uint32 s24;
uint32 s25;
uint32 s26;
uint32 s27;
uint32 s28;
uint32 s29;
uint32 s30;
uint32 s31;
#endif
struct ExceptionStackFrameFpu ExErrorStackContex;
};
uint8 KTaskStackSetup(struct TaskDescriptor *task)
{
struct StackRegisterContent* StackContex;
int i = 0;
task->stack_point = (uint8 *)ALIGN_MEN_DOWN((x_ubase)(task->task_base_info.stack_start + task->task_base_info.stack_depth), 8);
task->stack_point -= sizeof(struct StackRegisterContent);
StackContex = (struct StackRegisterContent*)task->stack_point;
for (i = 0; i < sizeof(struct StackRegisterContent) / sizeof(uint32); i++)
((uint32 *)StackContex)[i] = 0xfadeface;
StackContex->ExErrorStackContex.r0 = (unsigned long)task->task_base_info.func_param;
StackContex->ExErrorStackContex.pc = (unsigned long)task->task_base_info.func_entry ;
StackContex->ExErrorStackContex.psr = 0x01000000L;
StackContex->primask = 0x00000000L;
#ifdef SEPARATE_COMPILE
if(task->task_dync_sched_member.isolation_flag == 1 ) {
StackContex->ExErrorStackContex.lr = (unsigned long)USERSPACE->us_taskquit;
} else {
StackContex->ExErrorStackContex.lr = (unsigned long)KTaskQuit;
}
#else
StackContex->ExErrorStackContex.lr = (unsigned long)KTaskQuit;
#endif
#if USE_FPU
StackContex->flag = 0;
#endif
return EOK;
}
void HwExceptionInstall(x_err_t (*exception_handle)(void *context))
{
ExceptionHook = exception_handle;
}
#define SCB_CFSR (*(volatile const unsigned *)0xE000ED28)
#define SCB_HFSR (*(volatile const unsigned *)0xE000ED2C)
#define SCB_MMAR (*(volatile const unsigned *)0xE000ED34)
#define SCB_BFAR (*(volatile const unsigned *)0xE000ED38)
#define SCB_AIRCR (*(volatile unsigned long *)0xE000ED0C)
#define SCB_RESET_VALUE 0x05FA0004
#define SCB_CFSR_MFSR (*(volatile const unsigned char*)0xE000ED28)
#define SCB_CFSR_BFSR (*(volatile const unsigned char*)0xE000ED29)
#define SCB_CFSR_UFSR (*(volatile const unsigned short*)0xE000ED2A)
#ifdef TOOL_SHELL
static void UsageFaultTrack(void)
{
KPrintf("usage fault:\n");
KPrintf("SCB_CFSR_UFSR:0x%02X ", SCB_CFSR_UFSR);
if(SCB_CFSR_UFSR & (1<<0))
KPrintf("UNDEFINSTR ");
if(SCB_CFSR_UFSR & (1<<1))
KPrintf("INVSTATE ");
if(SCB_CFSR_UFSR & (1<<2))
KPrintf("INVPC ");
if(SCB_CFSR_UFSR & (1<<3))
KPrintf("NOCP ");
if(SCB_CFSR_UFSR & (1<<8))
KPrintf("UNALIGNED ");
if(SCB_CFSR_UFSR & (1<<9))
KPrintf("DIVBYZERO ");
KPrintf("\n");
}
static void BusFaultTrack(void)
{
KPrintf("bus fault:\n");
KPrintf("SCB_CFSR_BFSR:0x%02X ", SCB_CFSR_BFSR);
if(SCB_CFSR_BFSR & (1<<0))
KPrintf("IBUSERR ");
if(SCB_CFSR_BFSR & (1<<1))
KPrintf("PRECISERR ");
if(SCB_CFSR_BFSR & (1<<2))
KPrintf("IMPRECISERR ");
if(SCB_CFSR_BFSR & (1<<3))
KPrintf("UNSTKERR ");
if(SCB_CFSR_BFSR & (1<<4))
KPrintf("STKERR ");
if(SCB_CFSR_BFSR & (1<<7))
KPrintf("SCB->BFAR:%08X\n", SCB_BFAR);
else
KPrintf("\n");
}
static void MemManageFaultTrack(void)
{
KPrintf("mem manage fault:\n");
KPrintf("SCB_CFSR_MFSR:0x%02X ", SCB_CFSR_MFSR);
if(SCB_CFSR_MFSR & (1<<0))
KPrintf("IACCVIOL ");
if(SCB_CFSR_MFSR & (1<<1))
KPrintf("DACCVIOL ");
if(SCB_CFSR_MFSR & (1<<3))
KPrintf("MUNSTKERR ");
if(SCB_CFSR_MFSR & (1<<4))
KPrintf("MSTKERR ");
if(SCB_CFSR_MFSR & (1<<7))
KPrintf("SCB->MMAR:%08X\n", SCB_MMAR);
else
KPrintf("\n");
}
static void HardFaultTrack(void)
{
if(SCB_HFSR & (1UL<<1))
KPrintf("failed vector fetch\n");
if(SCB_HFSR & (1UL<<30)) {
if(SCB_CFSR_BFSR)
BusFaultTrack();
if(SCB_CFSR_MFSR)
MemManageFaultTrack();
if(SCB_CFSR_UFSR)
UsageFaultTrack();
}
if(SCB_HFSR & (1UL<<31))
KPrintf("debug event\n");
}
#endif
struct ExceptionInfo
{
uint32 ExcReturn;
struct StackRegisterContent stackframe;
};
void HwHardFaultException(struct ExceptionInfo *ExceptionInfo)
{
extern long ShowTask(void);
struct ExErrorStackContex* ExceptionStack = (struct ExErrorStackContex*)&ExceptionInfo->stackframe.ExErrorStackContex;
struct StackRegisterContent* context = (struct StackRegisterContent*)&ExceptionInfo->stackframe;
if (ExceptionHook != NONE) {
x_err_t result = ExceptionHook(ExceptionStack);
if (result == EOK) return;
}
KPrintf("psr: 0x%08x\n", context->ExErrorStackContex.psr);
KPrintf("r00: 0x%08x\n", context->ExErrorStackContex.r0);
KPrintf("r01: 0x%08x\n", context->ExErrorStackContex.r1);
KPrintf("r02: 0x%08x\n", context->ExErrorStackContex.r2);
KPrintf("r03: 0x%08x\n", context->ExErrorStackContex.r3);
KPrintf("r04: 0x%08x\n", context->r4);
KPrintf("r05: 0x%08x\n", context->r5);
KPrintf("r06: 0x%08x\n", context->r6);
KPrintf("r07: 0x%08x\n", context->r7);
KPrintf("r08: 0x%08x\n", context->r8);
KPrintf("r09: 0x%08x\n", context->r9);
KPrintf("r10: 0x%08x\n", context->r10);
KPrintf("r11: 0x%08x\n", context->r11);
//KPrintf("exc_ret: 0x%08x\n", context->exc_ret);
KPrintf("r12: 0x%08x\n", context->ExErrorStackContex.r12);
KPrintf(" lr: 0x%08x\n", context->ExErrorStackContex.lr);
KPrintf(" pc: 0x%08x\n", context->ExErrorStackContex.pc);
if (ExceptionInfo->ExcReturn & (1 << 2)) {
KPrintf("hard fault on task: %s\r\n\r\n", GetKTaskDescriptor()->task_base_info.name);
#ifdef TOOL_SHELL
ShowTask();
#endif
} else {
KPrintf("hard fault on handler\r\n\r\n");
}
if ( (ExceptionInfo->ExcReturn & 0x10) == 0)
KPrintf("FPU active!\r\n");
#ifdef TOOL_SHELL
HardFaultTrack();
#endif
while (1);
}
void UpdateRunningTask(void)
{
RunningKTask = (struct TaskDescriptor *)InterruptToKtaskDescriptor;
}
void MemFaultExceptionPrint(struct ExceptionInfo *ExceptionInfo)
{
extern long ShowTask(void);
struct ExErrorStackContex* ExceptionStack = (struct ExErrorStackContex*)&ExceptionInfo->stackframe.ExErrorStackContex;
struct StackRegisterContent* context = (struct StackRegisterContent*)&ExceptionInfo->stackframe;
if (ExceptionHook != NONE) {
x_err_t result = ExceptionHook(ExceptionStack);
if (result == EOK) return;
}
KPrintf("psr: 0x%08x\n", context->ExErrorStackContex.psr);
KPrintf("r00: 0x%08x\n", context->ExErrorStackContex.r0);
KPrintf("r01: 0x%08x\n", context->ExErrorStackContex.r1);
KPrintf("r02: 0x%08x\n", context->ExErrorStackContex.r2);
KPrintf("r03: 0x%08x\n", context->ExErrorStackContex.r3);
KPrintf("r04: 0x%08x\n", context->r4);
KPrintf("r05: 0x%08x\n", context->r5);
KPrintf("r06: 0x%08x\n", context->r6);
KPrintf("r07: 0x%08x\n", context->r7);
KPrintf("r08: 0x%08x\n", context->r8);
KPrintf("r09: 0x%08x\n", context->r9);
KPrintf("r10: 0x%08x\n", context->r10);
KPrintf("r11: 0x%08x\n", context->r11);
KPrintf("exc_ret: 0x%08x\n", ExceptionInfo->ExcReturn);
KPrintf("r12: 0x%08x\n", context->ExErrorStackContex.r12);
KPrintf(" lr: 0x%08x\n", context->ExErrorStackContex.lr);
KPrintf(" pc: 0x%08x\n", context->ExErrorStackContex.pc);
if (ExceptionInfo->ExcReturn & (1 << 2)) {
KPrintf("hard fault on task: %s\r\n\r\n", GetKTaskDescriptor()->task_base_info.name);
#ifdef TOOL_SHELL
ShowTask();
#endif
} else {
KPrintf("hard fault on handler\r\n\r\n");
}
if ((ExceptionInfo->ExcReturn & 0x10) == 0)
KPrintf("FPU active!\r\n");
#ifdef TOOL_SHELL
HardFaultTrack();
#endif
while (1);
}
void MemFaultHandle(uintptr_t *sp)
{
#ifdef TASK_ISOLATION
struct TaskDescriptor *task;
task = GetKTaskDescriptor();
if( task->task_dync_sched_member.isolation_flag == 1){
KPrintf("\nSegmentation fault, task: %s\n", task->task_base_info.name);
KTaskQuit();
}
else
#endif
{
MemFaultExceptionPrint((struct ExceptionInfo *)sp);
}
}
__attribute__((weak)) void HwCpuReset(void)
{
SCB_AIRCR = SCB_RESET_VALUE;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), Reboot, HwCpuReset, reset machine );

View File

@ -0,0 +1,58 @@
/*
* 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.
*/
#ifndef __INC_SVC_HANDLE_H__
#define __INC_SVC_HANDLE_H__
#if defined ( __VFP_FP__ ) && !defined(__SOFTFP__)
#define INT_FPU_REGS (1)
#else
#define INT_FPU_REGS (0)
#endif
#define HW_INT_REGS (8)
#define SW_INT_REGS (9 + INT_FPU_REGS)
#define REG_INT_R0 (SW_INT_REGS + 0) /* R0 */
#define REG_INT_R1 (SW_INT_REGS + 1) /* R1 */
#define REG_INT_R2 (SW_INT_REGS + 2) /* R2 */
#define REG_INT_R3 (SW_INT_REGS + 3) /* R3 */
#define REG_INT_R12 (SW_INT_REGS + 4) /* R12 */
#define REG_INT_R14 (SW_INT_REGS + 5) /* R14 = LR */
#define REG_INT_PC (SW_INT_REGS + 6) /* R15 = PC */
#define REG_INT_XPSR (SW_INT_REGS + 7) /* xPSR */
#if defined ( __VFP_FP__ ) && !defined(__SOFTFP__)
#define REG_INT_FPU_FLAG (0) /* fpu flag */
#define REG_INT_PRIMASK (1) /* PRIMASK */
#define REG_INT_R4 (2) /* R4 */
#define REG_INT_R5 (3) /* R5 */
#define REG_INT_R6 (4) /* R6 */
#define REG_INT_R7 (5) /* R7 */
#define REG_INT_R8 (6) /* R8 */
#define REG_INT_R9 (7) /* R9 */
#define REG_INT_R10 (8) /* R10 */
#define REG_INT_R11 (9) /* R11 */
#else
#define REG_INT_PRIMASK (0) /* PRIMASK */
#define REG_INT_R4 (1) /* R4 */
#define REG_INT_R5 (2) /* R5 */
#define REG_INT_R6 (3) /* R6 */
#define REG_INT_R7 (4) /* R7 */
#define REG_INT_R8 (5) /* R8 */
#define REG_INT_R9 (6) /* R9 */
#define REG_INT_R10 (7) /* R10 */
#define REG_INT_R11 (8) /* R11 */
#endif
#endif

View File

@ -21,19 +21,37 @@
void __attribute__((naked)) HwInterruptcontextSwitch(x_ubase from, x_ubase to, struct TaskDescriptor *to_task, void *context)
{
asm volatile ("PUSH {R4}");
asm volatile ("PUSH {R5}");
asm volatile ("LDR r4, =KtaskSwitchInterruptFlag");
asm volatile ("LDR r5, [r4]");
asm volatile ("CMP r5, #1");
asm volatile ("POP {R5}");
asm volatile ("POP {R4}");
asm volatile ("BEQ Arm32SwitchReswitch");
asm volatile ("PUSH {R4}");
asm volatile ("PUSH {R5}");
asm volatile ("LDR r4, =KtaskSwitchInterruptFlag");
asm volatile ("MOV r5, #1");
asm volatile ("STR r5, [r4]");
asm volatile ("LDR r4, =InterruptFromKtask");
asm volatile ("STR r0, [r4]");
asm volatile ("POP {R5}");
asm volatile ("POP {R4}");
asm volatile ("B Arm32SwitchReswitch");
}
void __attribute__((naked)) Arm32SwitchReswitch()
{
asm volatile ("PUSH {R4}");
asm volatile ("LDR r4, =InterruptToKtask");
asm volatile ("STR r1, [r4]");
asm volatile ("LDR r4, =InterruptToKtaskDescriptor");
@ -41,6 +59,9 @@ void __attribute__((naked)) Arm32SwitchReswitch()
asm volatile ("LDR r0, =" NVIC_INT_CTRL);
asm volatile ("LDR r1, =" NVIC_PENDSVSET);
asm volatile ("STR r1, [r0]");
asm volatile ("POP {R4}");
asm volatile ("BX LR");
}

View File

@ -604,6 +604,41 @@ out:
return ret;
}
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(i2c_drv);
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
if (configure_info->private_data) {
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
return EOK;
}
KPrintf("I2cInit need set i2c dev addr\n");
return ERROR;
}
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
switch (configure_info->configure_cmd)
{
case OPE_INT:
ret = I2cInit(i2c_drv, configure_info);
break;
default:
break;
}
return ret;
}
/*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done =
{
@ -681,6 +716,8 @@ int Stm32HwI2cInit(void)
#ifdef BSP_USING_I2C1
I2cGpioInit(&i2c_bus_param);
i2c_driver.configure = I2cDrvConfigure;
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
if (EOK != ret) {
KPrintf("board_i2c_Init error ret %u\n", ret);

View File

@ -512,6 +512,41 @@ out:
return ret;
}
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(i2c_drv);
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
if (configure_info->private_data) {
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
return EOK;
}
KPrintf("I2cInit need set i2c dev addr\n");
return ERROR;
}
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
switch (configure_info->configure_cmd)
{
case OPE_INT:
ret = I2cInit(i2c_drv, configure_info);
break;
default:
break;
}
return ret;
}
/*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done =
{
@ -589,6 +624,8 @@ int HwI2cInit(void)
#ifdef BSP_USING_I2C1
I2cGpioInit(&i2c_bus_param);
i2c_driver.configure = I2cDrvConfigure;
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
if (EOK != ret) {
KPrintf("board_i2c_Init error ret %u\n", ret);

View File

@ -0,0 +1,248 @@
#
# Automatically generated file; DO NOT EDIT.
# XiUOS Project Configuration
#
CONFIG_BOARD_CORTEX_M3_EVB=y
CONFIG_KERNEL_CONSOLE_DEVICE_NAME="uart0"
#CONFIG_LED0=24
#CONFIG_LED1=25
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_RISCV32=y
CONFIG_ARCH_CPU_32BIT=y
#
# cortex-m3-emulator feature
#
# CONFIG_BSP_USING_AUDIO is not set
# CONFIG_BSP_USING_CAMERA is not set
# CONFIG_BSP_USING_SDIO is not set
# CONFIG_BSP_USING_DMA is not set
CONFIG_BSP_USING_GPIO=y
# CONFIG_BSP_USING_I2C is not set
# CONFIG_BSP_USING_I2S is not set
# CONFIG_BSP_USING_LCD is not set
# CONFIG_BSP_USING_RTC is not set
# CONFIG_BSP_USING_SECURITY is not set
# CONFIG_BSP_USING_SPI is not set
CONFIG_BSP_USING_UART=y
# CONFIG_BSP_USING_UART_HS is not set
# CONFIG_BSP_USING_VIDEO is not set
# CONFIG_BSP_USING_WDT is not set
#
# General Purpose UARTs
#
CONFIG___STACKSIZE__=4096
#
# Hardware feature
#
CONFIG_RESOURCES_SERIAL=y
# CONFIG_SERIAL_USING_DMA=y
CONFIG_SERIAL_RB_BUFSZ=64
CONFIG_FS_VFS=n
# CONFIG_RESOURCES_HWTIMER is not set
# CONFIG_RESOURCES_I2C is not set
# CONFIG_RESOURCES_LCD is not set
# CONFIG_RESOURCES_SDIO is not set
# CONFIG_RESOURCES_TOUCH is not set
# CONFIG_RESOURCES_PIN=y
# CONFIG_RESOURCES_RTC is not set
# CONFIG_RESOURCES_SPI is not set
#CONFIG_RESOURCES_SPI_SD is not set
#CONFIG_RESOURCES_SPI_SFUD is not set
# SFUD_USING_SFDP is not set
# SFUD_USING_FLASH_INFO_TABLE is not set
# SFUD_DEBUG_LOG is not set
# CONFIG_RESOURCES_WDT is not set
# CONFIG_RESOURCES_USB is not set
# CONFIG_RESOURCES_USB_HOST is not set
# CONFIG_UDISK_MOUNTPOINT is not set
# CONFIG_USBH_MSTORAGE is not set
# CONFIG_RESOURCES_USB_DEVICE is not set
# CONFIG_USBD_THREAD_STACK_SZ is not set
#
# Kernel feature
#
#
# Kernel Device Object
#
CONFIG_KERNEL_DEVICE=y
CONFIG_KERNEL_CONSOLE=y
CONFIG_KERNEL_CONSOLEBUF_SIZE=128
#
# Task feature
#
CONFIG_SCHED_POLICY_RR_REMAINSLICE=y
# CONFIG_SCHED_POLICY_RR is not set
# CONFIG_SCHED_POLICY_FIFO is not set
#
# Memory Management
#
# CONFIG_KERNEL_MEMBLOCK is not set
CONFIG_MEM_ALIGN_SIZE=4
CONFIG_MM_PAGE_SIZE=1024
#
# Using small memory allocator
#
CONFIG_KERNEL_SMALL_MEM_ALLOC=y
CONFIG_SMALL_NUMBER_32B=32
CONFIG_SMALL_NUMBER_64B=16
#
# Inter-Task communication
#
# CONFIG_KERNEL_SEMAPHORE=y
# CONFIG_KERNEL_MUTEX=y
CONFIG_KERNEL_EVENT=n
CONFIG_KERNEL_MESSAGEQUEUE=n
CONFIG_KTASK_PRIORITY_8=y
CONFIG_KTASK_PRIORITY_MAX=8
CONFIG_TICK_PER_SECOND=100
# CONFIG_KERNEL_STACK_OVERFLOW_CHECK=y
CONFIG_KERNEL_BANNER=y
# CONFIG_KERNEL_HOOK is not set
# CONFIG_KERNEL_SOFTTIMER=y
# CONFIG_KERNEL_IDLE_HOOK=y
# CONFIG_IDEL_HOOK_LIST_SIZE=4
CONFIG_IDLE_KTASK_STACKSIZE=512
CONFIG_ZOMBIE_KTASK_STACKSIZE=512
# CONFIG_KERNEL_TASK_ISOLATION is not set
#
# Memory Management
#
# CONFIG_KERNEL_MEMBLOCK is not set
#
# Command shell
#
CONFIG_TOOL_SHELL=y
CONFIG_SHELL_TASK_PRIORITY=4
CONFIG_SHELL_TASK_STACK_SIZE=2048
#
# User Control
#
CONFIG_SHELL_DEFAULT_USER="letter"
CONFIG_SHELL_DEFAULT_USER_PASSWORD=""
CONFIG_SHELL_LOCK_TIMEOUT=10000
CONFIG_SHELL_ENTER_CR_AND_LF=y
# CONFIG_SHELL_ENTER_CRLF is not set
CONFIG_SHELL_ENTER_CR=y
CONFIG_SHELL_ENTER_LF=y
CONFIG_SHELL_MAX_NUMBER=5
CONFIG_SHELL_PARAMETER_MAX_NUMBER=8
CONFIG_SHELL_HISTORY_MAX_NUMBER=5
CONFIG_SHELL_PRINT_BUFFER=128
CONFIG_SHELL_USING_CMD_EXPORT=y
# CONFIG_SHELL_HELP_LIST_USER is not set
CONFIG_SHELL_HELP_SHOW_PERMISSION=y
# CONFIG_SHELL_HELP_LIST_VAR is not set
# CONFIG_SHELL_HELP_LIST_KEY is not set
#CONFIG_KERNEL_QUEUEMANAGE=y
# CONFIG_KERNEL_WORKQUEUE is not set
CONFIG_WORKQUEUE_KTASK_STACKSIZE=256
CONFIG_WORKQUEUE_KTASK_PRIORITY=2
CONFIG_QUEUE_MAX=2
CONFIG_KERNEL_WAITQUEUE=y
CONFIG_KERNEL_DATAQUEUE=y
# CONFIG_KERNEL_CIRCULAR_AREA is not set
# CONFIG_KERNEL_AVL_TREE is not set
CONFIG_NAME_MAX=32
CONFIG_ALIGN_SIZE=8
CONFIG_KERNEL_COMPONENTS_INIT=n
CONFIG_KERNEL_USER_MAIN=y
CONFIG_MAIN_KTASK_STACK_SIZE=2048
CONFIG_ENV_INIT_KTASK_STACK_SIZE=2048
CONFIG_MAIN_KTASK_PRIORITY=3
# CONFIG_USER_TEST is not set
# CONFIG_TOOL_TEST_SEM is not set
# CONFIG_TOOL_TEST_MUTEX is not set
# CONFIG_TOOL_TEST_EVENT is not set
# CONFIG_TOOL_TEST_MSG is not set
# CONFIG_TOOL_TEST_AVLTREE is not set
# CONFIG_TEST_CRICULAR_AREA is not set
# CONFIG_TOOL_TEST_MEM is not set
# CONFIG_TOOL_TEST_TIMER is not set
# CONFIG_TOOL_TEST_IWG is not set
# CONFIG_TOOL_TEST_REALTIME is not set
# CONFIG_TOOL_TEST_DBG is not set
# CONFIG_TOOL_TEST_SCHED is not set
# CONFIG_KERNEL_DEBUG is not set
#CONFIG_DEBUG_INIT_CONFIG=y
#CONFIG_DBG_INIT=1
#CONFIG_ARCH_SMP=y
#CONFIG_CPUS_NR=2
#
# hash table config
#
CONFIG_ID_HTABLE_SIZE=4
CONFIG_ID_NUM_MAX=16
#
# File system
#
CONFIG_FS_DFS=n
#CONFIG_DFS_USING_WORKDIR=y
#CONFIG_FS_DFS_DEVFS=y
#
# Fat filesystem
#
#
# IOT-Device File system
#
#
# Lwext4 filesystem
#
#
# APP Framework
#
#
# Perception
#
# CONFIG_PERCEPTION_SENSORDEVICE is not set
#
# connection
#
# CONFIG_CONNECTION_AT is not set
# CONFIG_CONNECTION_MQTT is not set
#
# medium communication
#
#
# Intelligence
#
#
# Control
#
#
# Lib
#
CONFIG_LIB=y
CONFIG_LIB_POSIX=y
CONFIG_LIB_NEWLIB=y
# CONFIG_LITTLEVGL2RTT_USING_DEMO=y
#
# Security
#

View File

@ -0,0 +1,56 @@
mainmenu "XiUOS Project Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config KERNEL_DIR
string
option env="KERNEL_ROOT"
default "../.."
config BOARD_CORTEX_M0_EVB
bool
select ARCH_ARM
default y
config KERNEL_CONSOLE_DEVICE_NAME
string
default "uart0"
source "$KERNEL_DIR/arch/Kconfig"
menu "cortex-m0 emulator feature"
source "$BSP_DIR/third_party_driver/Kconfig"
menu "config default board resources"
menu "config board app name"
config BOARD_APP_NAME
string "config board app name"
default "/XiUOS_cortex-m0-emulator_app.bin"
endmenu
menu "config board service table"
config SERVICE_TABLE_ADDRESS
hex "board service table address"
default 0x2007F0000
endmenu
endmenu
config __STACKSIZE__
int "stack size for interrupt"
default 4096
endmenu
menu "Hardware feature"
source "$KERNEL_DIR/resources/Kconfig"
endmenu
source "$KERNEL_DIR/Kconfig"

View File

@ -0,0 +1,5 @@
SRC_DIR := third_party_driver
SRC_FILES := board.c connect_uart.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,187 @@
# 从零开始构建矽璓工业物联操作系统使用ARM架构的cortex-m0 emulator
# cortex-m0 emulator
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓XiUOS是一款面向智慧车间的工业物联网操作系统主要由一个极简的微型实时操作系统内核和其上的工业物联框架构成通过高效管理工业物联网设备、支撑工业物联应用在生产车间内实现智能化的“感知环境、联网传输、知悉识别、控制调整”促进以工业设备和工业控制系统为核心的人、机、物深度互联帮助提升生产线的数字化和智能化水平。
## 1. 简介
QEMU 是一个通用的开源模拟器和虚拟化工具。目前QEMU已经可以较完整的支持ARM cortex-m0架构。XiUOS同样支持运行在QEMU上
| 硬件 | 描述 |
| -- | -- |
|芯片型号| microbit nRF51 |
|架构| cortex-m0 |
|主频| 50MHz |
|片内SRAM| 64KB |
| 外设支持 | UART |
XiUOS板级当前支持使用UART。
## 2. 开发环境搭建
### 推荐使用:
**操作系统:** ubuntu18.04 [https://ubuntu.com/download/desktop](https://ubuntu.com/download/desktop)
更新`ubuntu 18.04`源的方法:(根据自身情况而定,可以不更改)
第一步:打开sources.list文件
```c
sudo vim /etc/apt/sources.list
```
第二步:将以下内容复制到sources.list文件
```c
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
```
第三步:更新源和系统软件
```c
sudo apt-get update
sudo apt-get upgrade
```
**开发工具推荐使用 VSCode VScode下载地址为** VSCode [https://code.visualstudio.com/](https://code.visualstudio.com/),推荐下载地址为 [http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb](http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb)
### 依赖包安装:
```
$ sudo apt install build-essential pkg-config git
$ sudo apt install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev
```
**XiUOS操作系统源码下载** XiUOS [https://forgeplus.trustie.net/projects/xuos/xiuos](https://forgeplus.trustie.net/projects/xuos/xiuos)
新建一个空文件夹并进入文件夹中,并下载源码,具体命令如下:
```c
mkdir test && cd test
git clone https://git.trustie.net/xuos/xiuos.git
```
打开源码文件包可以看到以下目录:
| 名称 | 说明 |
| -- | -- |
| application | 应用代码 |
| board | 板级支持包 |
| framework | 应用框架 |
| fs | 文件系统 |
| kernel | 内核源码 |
| resources | 驱动文件 |
| tool | 系统工具 |
使用VScode打开代码具体操作步骤为在源码文件夹下打开系统终端输入`code .`即可打开VScode开发环境如下图所示
<div align= "center">
<img src = img/vscode.jpg width =1000>
</div>
### 裁减配置工具的下载
裁减配置工具:
**工具地址:** kconfig-frontends [https://forgeplus.trustie.net/projects/xuos/kconfig-frontends](https://forgeplus.trustie.net/projects/xuos/kconfig-frontends),下载与安装的具体命令如下:
```c
mkdir kfrontends && cd kfrontends
git clone https://git.trustie.net/xuos/kconfig-frontends.git
```
下载源码后按以下步骤执行软件安装:
```c
cd kconfig-frontends
./xs_build.sh
```
### 编译工具链:
ARM arm-none-eabi(`gcc version 6.3.1`)默认安装到Ubuntu的/usr/bin/arm-none-eabi-,使用如下命令行下载和安装。
```shell
$ sudo apt install gcc-arm-none-eabi
```
## 编译说明
### 编辑环境:`Ubuntu18.04`
### 编译工具链:`arm-none-eabi-gcc`
使用`VScode`打开工程的方法有多种,本文介绍一种快捷键,在项目目录下将`code .`输入linux系统命令终端即可打开目标项目
编译步骤:
1.在VScode命令终端中执行以下命令生成配置文件
```c
make BOARD=cortex-m0-emulator menuconfig
```
2.在menuconfig界面配置需要关闭和开启的功能按回车键进入下级菜单按Y键选中需要开启的功能按N键选中需要关闭的功能配置结束后保存并退出本例旨在演示简单的输出例程所以没有需要配置的选项双击快捷键ESC退出配置
![menuconfig](img/menuconfig.png)
退出时选择`yes`保存上面所配置的内容,如下图所示:
![menuconfig1](img/menuconfig1.png)
3.继续执行以下命令,进行编译
```
make BOARD=cortex-m0-emulator
```
4.如果编译正确无误会产生XiUOS_cortex-m0-emulator.elf、XiUOS_cortex-m0-emulator.bin文件。
## 3. 运行
### 3.1 安装QEMU
```
sudo apt install qemu-system-arm
```
### 3.2 运行结果
通过以下命令启动QEMU并加载XiUOS ELF文件
```
qemu-system-arm -machine microbit -nographic -kernel build/XiUOS_cortex-m0-emulator.elf
```
QEMU运行起来后将会在终端上看到信息打印输出
![terminal](img/terminal.png)
### 3.3 调试
通过QEMU可以方便的对XiUOS进行调试首先安装gdb调试工具
```
sudo apt install gdb-multiarch
```
并通过以下命令启动QEMU
```
qemu-system-arm -machine microbit -nographic -kernel build/XiUOS_cortex-m0-emulator.elf -s -S
```
然后要重新开启另一个linux系统终端一个终端执行命令
```
gdb-multiarch build/XiUOS_cortex-m0-emulator.elf -ex "target remote localhost:1234"
```

View File

@ -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 board.c
* @brief support cortex-m3-emulator init configure and start-up
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-13
*/
#include <board.h>
#include <xiuos.h>
#include <device.h>
#include <arch_interrupt.h>
void SysTick_Handler(int irqn, void *arg)
{
TickAndTaskTimesliceUpdate();
}
DECLARE_HW_IRQ(SYSTICK_IRQN, SysTick_Handler, NONE);
void InitBoardHardware()
{
extern int InitHwUart(void);
InitHwUart();
InstallConsole(SERIAL_BUS_NAME_1, SERIAL_DRV_NAME_1, SERIAL_DEVICE_NAME_1);
InitBoardMemory((void*)LM3S_SRAM_START, (void*)LM3S_SRAM_END);
}

View File

@ -0,0 +1,38 @@
/*
* 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 board.h
* @brief define cortex-m3-emulator init configure and start-up function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-13
*/
#ifndef __BOARD_H__
#define __BOARD_H__
extern void *__bss_end;
extern void *_heap_end;
#define MEM_OFFSET 0x20001000
#define LM3S_SRAM_START ( ( ((unsigned long)(&__bss_end)) > MEM_OFFSET)? (unsigned long)(&__bss_end):(MEM_OFFSET) )
#define LM3S_SRAM_END ( &_heap_end )
#define BSP_USING_UART1
#define SERIAL_BUS_NAME_1 "uart0"
#define SERIAL_DRV_NAME_1 "uart0_drv"
#define SERIAL_DEVICE_NAME_1 "uart0_dev0"
#endif

View File

@ -0,0 +1,14 @@
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
export CFLAGS := -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb
export AFLAGS := -c -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
export LFLAGS := -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiUOS_cortex-m0-emulator.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
export CXXFLAGS := -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g
export APPLFLAGS := -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiUOS_app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
export DEFINES := -DHAVE_CCONFIG_H -g
export ARCH = arm
export MCU = cortex-m0

View File

@ -0,0 +1,331 @@
/*
* 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 connect_uart.c
* @brief support cortex_m3_emulator board uart function and register to bus framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-10
*/
#include <board.h>
#include <xiuos.h>
#include <device.h>
#include <inc/hw_types.h>
#include <driverlib/uart.h>
#include <driverlib/gpio.h>
#include <inc/hw_memmap.h>
#define NO_IMPL() KPrintf("%s is not implemented!\n", __func__)
#ifdef BSP_USING_UART1
static struct SerialBus serial_bus_1;
static struct SerialDriver serial_driver_1;
static struct SerialHardwareDevice serial_device_1;
#endif
#ifdef BSP_USING_UART2
static struct SerialBus serial_bus_2;
static struct SerialDriver serial_driver_2;
static struct SerialHardwareDevice serial_device_2;
#endif
static void SerialCfgParamCheck(struct SerialCfgParam *serial_cfg_default, struct SerialCfgParam *serial_cfg_new)
{
struct SerialDataCfg *data_cfg_default = &serial_cfg_default->data_cfg;
struct SerialDataCfg *data_cfg_new = &serial_cfg_new->data_cfg;
if ((data_cfg_default->serial_baud_rate != data_cfg_new->serial_baud_rate) && (data_cfg_new->serial_baud_rate)) {
data_cfg_default->serial_baud_rate = data_cfg_new->serial_baud_rate;
}
if ((data_cfg_default->serial_bit_order != data_cfg_new->serial_bit_order) && (data_cfg_new->serial_bit_order)) {
data_cfg_default->serial_bit_order = data_cfg_new->serial_bit_order;
}
if ((data_cfg_default->serial_buffer_size != data_cfg_new->serial_buffer_size) && (data_cfg_new->serial_buffer_size)) {
data_cfg_default->serial_buffer_size = data_cfg_new->serial_buffer_size;
}
if ((data_cfg_default->serial_data_bits != data_cfg_new->serial_data_bits) && (data_cfg_new->serial_data_bits)) {
data_cfg_default->serial_data_bits = data_cfg_new->serial_data_bits;
}
if ((data_cfg_default->serial_invert_mode != data_cfg_new->serial_invert_mode) && (data_cfg_new->serial_invert_mode)) {
data_cfg_default->serial_invert_mode = data_cfg_new->serial_invert_mode;
}
if ((data_cfg_default->serial_parity_mode != data_cfg_new->serial_parity_mode) && (data_cfg_new->serial_parity_mode)) {
data_cfg_default->serial_parity_mode = data_cfg_new->serial_parity_mode;
}
if ((data_cfg_default->serial_stop_bits != data_cfg_new->serial_stop_bits) && (data_cfg_new->serial_stop_bits)) {
data_cfg_default->serial_stop_bits = data_cfg_new->serial_stop_bits;
}
}
static void UartHandler(struct SerialBus *serial_bus, struct SerialDriver *serial_drv)
{
struct SerialHardwareDevice *serial_dev = (struct SerialHardwareDevice *)serial_bus->bus.owner_haldev;
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data;
uint32 status;
status = UARTIntStatus(serial_cfg->hw_cfg.serial_register_base, RET_TRUE);
/* clear interrupt status */
UARTIntClear(serial_cfg->hw_cfg.serial_register_base, status);
while (UARTCharsAvail(serial_cfg->hw_cfg.serial_register_base)) {
SerialSetIsr(serial_dev, SERIAL_EVENT_RX_IND);
}
}
#ifdef BSP_USING_UART1
void UartIsr1(int vector, void *param)
{
/* get serial bus 1 */
UartHandler(&serial_bus_1, &serial_driver_1);
}
DECLARE_HW_IRQ(UART1_IRQn, UartIsr1, NONE);
#endif
#ifdef BSP_USING_UART2
void UartIsr2(int irqno)
{
/* get serial bus 2 */
UartHandler(&serial_bus_2, &serial_driver_2);
}
#endif
static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(serial_drv);
return EOK;
}
static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operation_cmd)
{
NO_IMPL();
return 0;
}
static uint32 SerialDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
int serial_operation_cmd;
struct SerialDriver *serial_drv = (struct SerialDriver *)drv;
switch (configure_info->configure_cmd)
{
case OPE_INT:
ret = SerialInit(serial_drv, configure_info);
break;
case OPE_CFG:
serial_operation_cmd = *(int *)configure_info->private_data;
ret = SerialConfigure(serial_drv, serial_operation_cmd);
break;
default:
break;
}
return ret;
}
static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char c)
{
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
while (UARTCharPutNonBlocking(serial_cfg->hw_cfg.serial_register_base, c) == RET_FALSE);
return 0;
}
static int SerialGetChar(struct SerialHardwareDevice *serial_dev)
{
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
long val = UARTCharGetNonBlocking(serial_cfg->hw_cfg.serial_register_base);
if (val > 0)
return (int)val;
else
return -1;
}
static const struct SerialDataCfg data_cfg_init =
{
.serial_baud_rate = BAUD_RATE_115200,
.serial_data_bits = DATA_BITS_8,
.serial_stop_bits = STOP_BITS_1,
.serial_parity_mode = PARITY_NONE,
.serial_bit_order = BIT_ORDER_LSB,
.serial_invert_mode = NRZ_NORMAL,
.serial_buffer_size = SERIAL_RB_BUFSZ,
};
/*manage the serial device operations*/
static const struct SerialDrvDone drv_done =
{
.init = SerialInit,
.configure = SerialConfigure,
};
/*manage the serial device hal operations*/
static struct SerialHwDevDone hwdev_done =
{
.put_char = SerialPutChar,
.get_char = SerialGetChar,
};
static int BoardSerialBusInit(struct SerialBus *serial_bus, struct SerialDriver *serial_driver, const char *bus_name, const char *drv_name)
{
x_err_t ret = EOK;
/*Init the serial bus */
ret = SerialBusInit(serial_bus, bus_name);
if (EOK != ret) {
KPrintf("InitHwUart SerialBusInit error %d\n", ret);
return ERROR;
}
/*Init the serial driver*/
ret = SerialDriverInit(serial_driver, drv_name);
if (EOK != ret) {
KPrintf("InitHwUart SerialDriverInit error %d\n", ret);
return ERROR;
}
/*Attach the serial driver to the serial bus*/
ret = SerialDriverAttachToBus(drv_name, bus_name);
if (EOK != ret) {
KPrintf("InitHwUart SerialDriverAttachToBus error %d\n", ret);
return ERROR;
}
return ret;
}
/*Attach the serial device to the serial bus*/
static int BoardSerialDevBend(struct SerialHardwareDevice *serial_device, void *serial_param, const char *bus_name, const char *dev_name)
{
x_err_t ret = EOK;
ret = SerialDeviceRegister(serial_device, serial_param, dev_name);
if (EOK != ret) {
KPrintf("InitHwUart SerialDeviceInit device %s error %d\n", dev_name, ret);
return ERROR;
}
ret = SerialDeviceAttachToBus(dev_name, bus_name);
if (EOK != ret) {
KPrintf("InitHwUart SerialDeviceAttachToBus device %s error %d\n", dev_name, ret);
return ERROR;
}
return ret;
}
int InitHwUart(void)
{
x_err_t ret = EOK;
UARTlInitialize();
#ifdef BSP_USING_UART1
memset(&serial_bus_1, 0, sizeof(struct SerialBus));
memset(&serial_driver_1, 0, sizeof(struct SerialDriver));
memset(&serial_device_1, 0, sizeof(struct SerialHardwareDevice));
static struct SerialCfgParam serial_cfg_1;
memset(&serial_cfg_1, 0, sizeof(struct SerialCfgParam));
static struct SerialDevParam serial_dev_param_1;
memset(&serial_dev_param_1, 0, sizeof(struct SerialDevParam));
serial_driver_1.drv_done = &drv_done;
serial_driver_1.configure = &SerialDrvConfigure;
serial_device_1.hwdev_done = &hwdev_done;
serial_cfg_1.data_cfg = data_cfg_init;
serial_cfg_1.hw_cfg.serial_register_base = UART0_BASE;
serial_driver_1.private_data = (void *)&serial_cfg_1;
serial_dev_param_1.serial_work_mode = SIGN_OPER_INT_RX;
serial_device_1.haldev.private_data = (void *)&serial_dev_param_1;
/* enable UART0 clock */
// SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
/* set UART0 pinmux */
// GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/* Configure the UART for 115,200, 8-N-1 operation. */
// UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), serial_cfg_1.data_cfg.serial_baud_rate,
// (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
// UART_CONFIG_PAR_NONE));
ret = BoardSerialBusInit(&serial_bus_1, &serial_driver_1, SERIAL_BUS_NAME_1, SERIAL_DRV_NAME_1);
if (EOK != ret) {
KPrintf("InitHwUart uarths error ret %u\n", ret);
return ERROR;
}
ret = BoardSerialDevBend(&serial_device_1, (void *)&serial_cfg_1, SERIAL_BUS_NAME_1, SERIAL_DEVICE_NAME_1);
if (EOK != ret) {
KPrintf("InitHwUart uarths error ret %u\n", ret);
return ERROR;
}
#endif
#ifdef BSP_USING_UART2
memset(&serial_bus_2, 0, sizeof(struct SerialBus));
memset(&serial_driver_2, 0, sizeof(struct SerialDriver));
memset(&serial_device_2, 0, sizeof(struct SerialHardwareDevice));
static struct SerialCfgParam serial_cfg_2;
memset(&serial_cfg_2, 0, sizeof(struct SerialCfgParam));
static struct SerialDevParam serial_dev_param_2;
memset(&serial_dev_param_2, 0, sizeof(struct SerialDevParam));
serial_driver_2.drv_done = &drv_done;
serial_driver_2.configure = &SerialDrvConfigure;
serial_device_2.hwdev_done = &hwdev_done;
serial_cfg_2.data_cfg = data_cfg_init;
serial_cfg_2.hw_cfg.serial_register_base = UART1_BASE;
serial_driver_2.private_data = (void *)&serial_cfg_2;
serial_dev_param_2.serial_work_mode = SIGN_OPER_INT_RX | SIGN_OPER_POLL_RX;
serial_device_2.haldev.private_data = (void *)&serial_dev_param_2;
ret = BoardSerialBusInit(&serial_bus_2, &serial_driver_2, SERIAL_BUS_NAME_2, SERIAL_DRV_NAME_2);
if (EOK != ret) {
KPrintf("InitHwUart uarths error ret %u\n", ret);
return ERROR;
}
ret = BoardSerialDevBend(&serial_device_2, (void *)&serial_cfg_2, SERIAL_BUS_NAME_2, SERIAL_DEVICE_NAME_2);
if (EOK != ret) {
KPrintf("InitHwUart uarths error ret %u\n", ret);
return ERROR;
}
#endif
return ret;
}

View File

@ -0,0 +1,72 @@
MEMORY {
flash (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000
}
OUTPUT_FORMAT ("elf32-littlearm")
__SYSTEM_STACKSIZE__ = 0x400;
ENTRY(Reset_Handler)
SECTIONS {
.text : {
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
*(.text*)
*(.rodata*)
_shell_command_start = .;
KEEP (*(shellCommand))
_shell_command_end = .;
. = ALIGN(4);
__isrtbl_idx_start = .;
KEEP(*(.isrtbl.idx))
__isrtbl_start = .;
KEEP(*(.isrtbl))
__isrtbl_end = .;
. = ALIGN(4);
PROVIDE(g_service_table_start = ABSOLUTE(.));
KEEP(*(.g_service_table))
PROVIDE(g_service_table_end = ABSOLUTE(.));
PROVIDE(_etext = ABSOLUTE(.));
_etext = .;
} > flash = 0
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
_sidata = .;
} > flash
__exidx_end = .;
.data : AT (_sidata) {
. = ALIGN(4);
_sdata = .;
*(.data*)
. = ALIGN(4);
_edata = .;
} > sram
.bss : {
. = ALIGN(4);
_sbss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
} > sram
__bss_end = .;
__end = .;
.stack ORIGIN(sram) + LENGTH(sram) - __SYSTEM_STACKSIZE__ :
{
PROVIDE( _heap_end = . );
. = __SYSTEM_STACKSIZE__;
PROVIDE( _sp = . );
} >sram
}

View File

@ -0,0 +1,3 @@
SRC_DIR := driverlib
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := uart.c
# SRC_FILES := uart.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,13 @@
#pragma once
/* GPIO */
#define GPIO_DIRSET ADDR(0x50000518)
#define GPIO_DIRCLR ADDR(0x5000051c)
#define GPIO_PINCNF ARRAY(0x50000700)
#define GPIO_PINCNF_PULL_Pos 2
#define GPIO_PINCNF_PULL_Wid 2
#define GPIO_Pullup 0x3
#define GPIO_PINCNF_DRIVE_Pos 8
#define GPIO_PINCNF_DRIVE_Wid 3
#define GPIO_S0D1 0x6 // Open drain

View File

@ -0,0 +1,23 @@
#define BIT(i) (1 << (i))
#define SET_BIT(reg, n) reg |= BIT(n)
#define CLR_BIT(reg, n) reg &= ~BIT(n)
#define SET_FIELD(reg, field, val) \
reg = (reg & ~MASK(field)) | FIELD(field, val)
#define GET_FIELD(reg, field) \
((reg >> field##_Pos) & MASK0(field))
#define FIELD(field, val) \
(((val) & MASK0(field)) << field##_Pos)
#define MASK(field) (MASK0(field) << field##_Pos)
#define MASK0(field) (~((-2) << (field##_Wid-1)))
#define SET_BYTE(reg, n, v) \
reg = (reg & ~(0xff << 8*n)) | ((v & 0xff) << 8*n)
#define ADDR(x) (* (unsigned volatile *) (x))
#define ARRAY(x) ((unsigned volatile *) (x))

View File

@ -0,0 +1,156 @@
//*****************************************************************************
//
// uart.c - Driver for the UART.
//
// Copyright (c) 2005-2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 10636 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup uart_api
//! @{
//
//*****************************************************************************
#include <stdarg.h>
#include "inc/hw_types.h"
#include "inc/hw_nvic.h"
#include "driverlib/uart.h"
#include "driverlib/gpio.h"
#include "driverlib/opt.h"
//*****************************************************************************
//
// This is a mapping between interrupt number (for the peripheral interrupts
// only) and the register that contains the interrupt enable for that
// interrupt.
//
//*****************************************************************************
static const unsigned long g_pulEnRegs[] =
{
NVIC_EN0, NVIC_EN1, NVIC_EN2, NVIC_EN3, NVIC_EN4
};
void UARTlInitialize(void) {
GPIO_DIRSET = BIT(USB_TX);
GPIO_DIRCLR = BIT(USB_RX);
SET_FIELD(GPIO_PINCNF[USB_TX], GPIO_PINCNF_PULL, GPIO_Pullup);
SET_FIELD(GPIO_PINCNF[USB_RX], GPIO_PINCNF_PULL, GPIO_Pullup);
UART_BAUDRATE = UART_BAUD_9600; // 9600 baud
UART_CONFIG = 0; // format 8N1
UART_PSELTXD = USB_TX; // choose pins
UART_PSELRXD = USB_RX;
/* Configure the uart device interrupt */
UART_ENABLE = UART_Enabled;
UART_INTENSET = (1 << 17) | (1<<2);
UART_STARTTX = 1;
UART_STARTRX = 1;
UART_RXDRDY = 0;
UART_TXDRDY = 1;
/* Enable the uart interrupt in NVIC */
HWREG(g_pulEnRegs[(18 - 16) / 32]) = 1 << ((18 - 16) & 31);
}
void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
unsigned long ulBaud, unsigned long ulConfig)
{
NO_IMPL();
}
tBoolean UARTCharsAvail(unsigned long ulBase)
{
return UART_RXDRDY;
}
long UARTCharGetNonBlocking(unsigned long ulBase)
{
char ch;
if (UART_RXDRDY) {
UART_RXDRDY = 0;
ch = UART_RXD;
return ch;
}
return -1;
}
long UARTCharGet(unsigned long ulBase)
{
char ch;
while (!UART_RXDRDY);
UART_RXDRDY = 0;
ch = UART_RXD;
return ch;
}
tBoolean UARTCharPutNonBlocking(unsigned long ulBase, unsigned char ucData)
{
if (UART_TXDRDY) {
UART_TXDRDY = 0;
UART_TXD = ucData;
return true;
}
return false;
}
void UARTCharPut(unsigned long ulBase, unsigned char ucData)
{
while (!UART_TXDRDY);
UART_TXDRDY = 0;
UART_TXD = ucData;
}
void UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
{
NO_IMPL();
}
void UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
{
NO_IMPL();
}
unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked)
{
return UART_INTENCLR;
}
void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags)
{
UART_INTENCLR = ulIntFlags;
UART_INTENSET = ulIntFlags;
}

View File

@ -0,0 +1,70 @@
#ifndef __UART_H__
#define __UART_H__
#include <xs_base.h>
#define NO_IMPL() KPrintf("%s is not implemented!\n", __func__)
/* Device pins */
#define USB_TX 24
#define USB_RX 25
/* UART */
#define UART_STARTRX ADDR(0x40002000)
#define UART_STARTTX ADDR(0x40002008)
#define UART_RXDRDY ADDR(0x40002108)
#define UART_TXDRDY ADDR(0x4000211c)
#define UART_ENABLE ADDR(0x40002500)
#define UART_PSELTXD ADDR(0x4000250c)
#define UART_PSELRXD ADDR(0x40002514)
#define UART_RXD ADDR(0x40002518)
#define UART_TXD ADDR(0x4000251c)
#define UART_BAUDRATE ADDR(0x40002524)
#define UART_CONFIG ADDR(0x4000256c)
#define UART_INTEN ADDR(0x40002300)
#define UART_INTENSET ADDR(0x40002304)
#define UART_INTENCLR ADDR(0x40002308)
#define UART_Enabled 0x4
#define UART_INT_TXDRDY 7
#define UART_INT_RXDRDY 2
#define UART_BAUD_9600 0x00275000
#ifdef __cplusplus
extern "C"
{
#endif
extern void UARTlInitialize(void);
extern void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
unsigned long ulBaud, unsigned long ulConfig);
extern tBoolean UARTCharsAvail(unsigned long ulBase);
extern long UARTCharGetNonBlocking(unsigned long ulBase);
long UARTCharGet(unsigned long ulBase);
extern tBoolean UARTCharPutNonBlocking(unsigned long ulBase,
unsigned char ucData);
extern void UARTCharPut(unsigned long ulBase, unsigned char ucData);
extern void UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
extern void UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
extern unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked);
extern void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags);
#ifndef DEPRECATED
#define UARTCharNonBlockingGet(a) \
UARTCharGetNonBlocking(a)
#define UARTCharNonBlockingPut(a, b) \
UARTCharPutNonBlocking(a, b)
#endif
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // __UART_H__

View File

@ -0,0 +1,44 @@
//*****************************************************************************
//
// hw_memmap.h - Macros defining the memory map of Stellaris.
//
// Copyright (c) 2005-2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 10636 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
#ifndef __HW_MEMMAP_H__
#define __HW_MEMMAP_H__
#define UART0_BASE 0x40002000 // UART0
#endif

View File

@ -0,0 +1,212 @@
//*****************************************************************************
//
// hw_types.h - Common types and macros.
//
// Copyright (c) 2005-2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 10636 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
#ifndef __HW_TYPES_H__
#define __HW_TYPES_H__
//*****************************************************************************
//
// Define a boolean type, and values for true and false.
//
//*****************************************************************************
typedef unsigned char tBoolean;
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
//*****************************************************************************
//
// Macros for hardware access, both direct and via the bit-band region.
//
//*****************************************************************************
#define HWREG(x) \
(*((volatile unsigned long *)(x)))
#define HWREGH(x) \
(*((volatile unsigned short *)(x)))
#define HWREGB(x) \
(*((volatile unsigned char *)(x)))
#define HWREGBITW(x, b) \
HWREG(((unsigned long)(x) & 0xF0000000) | 0x02000000 | \
(((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
#define HWREGBITH(x, b) \
HWREGH(((unsigned long)(x) & 0xF0000000) | 0x02000000 | \
(((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
#define HWREGBITB(x, b) \
HWREGB(((unsigned long)(x) & 0xF0000000) | 0x02000000 | \
(((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
//*****************************************************************************
//
// Helper Macros for determining silicon revisions, etc.
//
// These macros will be used by Driverlib at "run-time" to create necessary
// conditional code blocks that will allow a single version of the Driverlib
// "binary" code to support multiple(all) Stellaris silicon revisions.
//
// It is expected that these macros will be used inside of a standard 'C'
// conditional block of code, e.g.
//
// if(CLASS_IS_SANDSTORM)
// {
// do some Sandstorm-class specific code here.
// }
//
// By default, these macros will be defined as run-time checks of the
// appropriate register(s) to allow creation of run-time conditional code
// blocks for a common DriverLib across the entire Stellaris family.
//
// However, if code-space optimization is required, these macros can be "hard-
// coded" for a specific version of Stellaris silicon. Many compilers will
// then detect the "hard-coded" conditionals, and appropriately optimize the
// code blocks, eliminating any "unreachable" code. This would result in
// a smaller Driverlib, thus producing a smaller final application size, but
// at the cost of limiting the Driverlib binary to a specific Stellaris
// silicon revision.
//
//*****************************************************************************
#ifndef CLASS_IS_SANDSTORM
#define CLASS_IS_SANDSTORM \
(((HWREG(SYSCTL_DID0) & SYSCTL_DID0_VER_M) == SYSCTL_DID0_VER_0) || \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
(SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_SANDSTORM)))
#endif
#ifndef CLASS_IS_FURY
#define CLASS_IS_FURY \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
(SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_FURY))
#endif
#ifndef CLASS_IS_DUSTDEVIL
#define CLASS_IS_DUSTDEVIL \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
(SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_DUSTDEVIL))
#endif
#ifndef CLASS_IS_TEMPEST
#define CLASS_IS_TEMPEST \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
(SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_TEMPEST))
#endif
#ifndef CLASS_IS_FIRESTORM
#define CLASS_IS_FIRESTORM \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
(SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_FIRESTORM))
#endif
#ifndef REVISION_IS_A0
#define REVISION_IS_A0 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_0))
#endif
#ifndef REVISION_IS_A1
#define REVISION_IS_A1 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_0))
#endif
#ifndef REVISION_IS_A2
#define REVISION_IS_A2 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_2))
#endif
#ifndef REVISION_IS_B0
#define REVISION_IS_B0 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVB | SYSCTL_DID0_MIN_0))
#endif
#ifndef REVISION_IS_B1
#define REVISION_IS_B1 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVB | SYSCTL_DID0_MIN_1))
#endif
#ifndef REVISION_IS_C0
#define REVISION_IS_C0 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_0))
#endif
#ifndef REVISION_IS_C1
#define REVISION_IS_C1 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_1))
#endif
#ifndef REVISION_IS_C2
#define REVISION_IS_C2 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_2))
#endif
#ifndef REVISION_IS_C3
#define REVISION_IS_C3 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_3))
#endif
#ifndef REVISION_IS_C5
#define REVISION_IS_C5 \
((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
(SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_5))
#endif
//*****************************************************************************
//
// Deprecated silicon class and revision detection macros.
//
//*****************************************************************************
#ifndef DEPRECATED
#define DEVICE_IS_SANDSTORM CLASS_IS_SANDSTORM
#define DEVICE_IS_FURY CLASS_IS_FURY
#define DEVICE_IS_REVA2 REVISION_IS_A2
#define DEVICE_IS_REVC1 REVISION_IS_C1
#define DEVICE_IS_REVC2 REVISION_IS_C2
#endif
#endif // __HW_TYPES_H__

View File

@ -0,0 +1,3 @@
SRC_DIR := Libraries
include $(KERNEL_ROOT)/compiler.mk

View File

@ -30,6 +30,23 @@ extern void timer_initialize(void);
extern void gapuino_sysinit(void);
extern unsigned int __bss_end__;
/* Return core id. */
uint32_t _procid( void )
{
uint32_t ulProcid = 0;
__asm__ volatile( "csrr %0, mhartid" : "=r"( ulProcid ) );
ulProcid = ulProcid & 0xf;
return ( ulProcid );
}
/* Return cluster id. */
uint32_t _clusterid( void )
{
uint32_t ulCluster = 0;
__asm__ volatile( "csrr %0, mhartid" : "=r"( ulCluster ) );
ulCluster = ulCluster >> 5;
return ( ulCluster );
}
void GapuinoStart(uint32_t mhartid)
{
@ -51,6 +68,7 @@ void InitBoardHardware(void)
timer_initialize();
KPrintf("memory address range: [0x%08x - 0x%08x], size: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, GAP8_SRAM_SIZE);
/* initialize memory system */
KPrintf("gap8 cluster id: [0x%x], _procid: [0x%x]\n", _clusterid(),_procid());
KPrintf("board init done.\n");
KPrintf("start kernel...\n");

View File

@ -500,6 +500,41 @@ out:
return ret;
}
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(i2c_drv);
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
if (configure_info->private_data) {
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
return EOK;
}
KPrintf("I2cInit need set i2c dev addr\n");
return ERROR;
}
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
switch (configure_info->configure_cmd)
{
case OPE_INT:
ret = I2cInit(i2c_drv, configure_info);
break;
default:
break;
}
return ret;
}
/*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done =
{
@ -577,6 +612,8 @@ int HwI2cInit(void)
#ifdef BSP_USING_I2C1
I2cGpioInit(&i2c_bus_param);
i2c_driver.configure = I2cDrvConfigure;
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
if (EOK != ret) {
KPrintf("board_i2c_Init error ret %u\n", ret);

View File

@ -600,6 +600,41 @@ out:
return ret;
}
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(i2c_drv);
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
if (configure_info->private_data) {
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
return EOK;
}
KPrintf("I2cInit need set i2c dev addr\n");
return ERROR;
}
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
switch (configure_info->configure_cmd)
{
case OPE_INT:
ret = I2cInit(i2c_drv, configure_info);
break;
default:
break;
}
return ret;
}
/*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done =
{
@ -677,6 +712,8 @@ int Stm32HwI2cInit(void)
#ifdef BSP_USING_I2C1
I2cGpioInit(&i2c_bus_param);
i2c_driver.configure = I2cDrvConfigure;
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
if (EOK != ret) {
KPrintf("board_i2c_Init error ret %u\n", ret);

Some files were not shown because too many files have changed in this diff Show More