23 changed files with 52 additions and 532 deletions
-
1ucomponents/preportional_valve/preportional_valve_ctrl.cpp
-
1ucomponents/preportional_valve/preportional_valve_ctrl.hpp
-
63usrc/app_main.cpp
-
4usrc/appdep.hpp
-
14usrc/apppublic/boardid.cpp
-
14usrc/apppublic/boardid.hpp
-
16usrc/base/appdep.hpp
-
53usrc/base/appthread/app_period_task_mgr.cpp
-
44usrc/base/appthread/app_period_task_mgr.hpp
-
2usrc/base/appthread/work_queue.cpp
-
32usrc/base/appthread/work_queue.hpp
-
37usrc/base/config_service.cpp
-
17usrc/base/config_service.hpp
-
8usrc/base/device_info.cpp
-
17usrc/base/device_info.hpp
-
21usrc/base/gflag/gflag.c
-
27usrc/base/gflag/gflag.h
-
64usrc/base/protocol_processer_mgr.cpp
-
27usrc/base/protocol_processer_mgr.hpp
-
51usrc/base/protocol_processer_utils.hpp
-
0usrc/base/utils/halutils.cpp
-
49usrc/base/utils/halutils.hpp
-
22usrc/project_configs.h
@ -0,0 +1,4 @@ |
|||||
|
#pragma once
|
||||
|
#include "ucomponents/ucomponents.hpp"
|
||||
|
#include "stm32halport/stm32halport.hpp"
|
||||
|
#include "stm32basic/stm32basic.hpp"
|
@ -0,0 +1,14 @@ |
|||||
|
#pragma once
|
||||
|
#include "boardid.hpp"
|
||||
|
|
||||
|
#include "appdep.hpp"
|
||||
|
#include "project_configs.h"
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
boardid::id_t BoardId_get() { |
||||
|
int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD; |
||||
|
if (*deviceId <= 0) { |
||||
|
return boardid::kunsupport; |
||||
|
} |
||||
|
return (boardid::id_t)*deviceId; |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
#pragma once
|
||||
|
#include "appdep.hpp"
|
||||
|
namespace iflytop { |
||||
|
namespace boardid { |
||||
|
typedef enum { |
||||
|
kunsupport = 0, |
||||
|
kbmainboard = 1, |
||||
|
kvalveboard = 2, |
||||
|
} id_t; |
||||
|
} |
||||
|
|
||||
|
boardid::id_t BoardId_get(); |
||||
|
|
||||
|
} // namespace iflytop
|
@ -1,16 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
|
|
||||
#include "project_configs.h"
|
|
||||
//
|
|
||||
#include "stm32basic/stm32basic.hpp"
|
|
||||
#include "stm32components/stm32components.hpp"
|
|
||||
#include "ucomponents/ucomponents.hpp"
|
|
||||
//
|
|
||||
#include "appthread/app_period_task_mgr.hpp"
|
|
||||
#include "device_info.hpp"
|
|
||||
#include "gflag/gflag.h"
|
|
||||
#include "protocol_processer_mgr.hpp"
|
|
||||
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
|
|
||||
#include "utils/halutils.hpp"
|
|
@ -1,53 +0,0 @@ |
|||||
#include "app_period_task_mgr.hpp"
|
|
||||
using namespace iflytop; |
|
||||
static osThreadId appPeriodTaskId; |
|
||||
|
|
||||
#define TAG "AppPeriodTaskMgr"
|
|
||||
|
|
||||
static int32_t haspassedms(uint32_t tp) { |
|
||||
uint32_t now = HAL_GetTick(); |
|
||||
if (now >= tp) { |
|
||||
return now - tp; |
|
||||
} else { |
|
||||
return 0xFFFFFFFF - tp + now; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
static void c_onappPeriodTaskThread(void const* argument) { AppPeriodTaskMgr::ins()->onThreadCB(); } |
|
||||
|
|
||||
void AppPeriodTaskMgr::initialize() {} |
|
||||
|
|
||||
void AppPeriodTaskMgr::regTask(const char* name, task_fn_t fn, void* cxt, int period) { |
|
||||
task[ntask].fn = fn; |
|
||||
task[ntask].taskname = name; |
|
||||
task[ntask].cxt = cxt; |
|
||||
task[ntask].period = period; |
|
||||
task[ntask].lastcalltp = HAL_GetTick(); |
|
||||
ZLOGI(TAG, "reg task %s", name); |
|
||||
ntask++; |
|
||||
} |
|
||||
void AppPeriodTaskMgr::regTask(const char* name, std::function<void()> fn, int period) { |
|
||||
task[ntask].exfn = fn; |
|
||||
task[ntask].taskname = name; |
|
||||
task[ntask].period = period; |
|
||||
task[ntask].lastcalltp = HAL_GetTick(); |
|
||||
ZLOGI(TAG, "reg task %s", name); |
|
||||
ntask++; |
|
||||
} |
|
||||
|
|
||||
void AppPeriodTaskMgr::onThreadCB() { |
|
||||
while (true) { |
|
||||
for (int i = 0; i < ntask; i++) { |
|
||||
if (haspassedms(task[i].lastcalltp) >= task[i].period) { |
|
||||
if (task[i].fn) task[i].fn(task[i].cxt); |
|
||||
if (task[i].exfn) task[i].exfn(); |
|
||||
task[i].lastcalltp = HAL_GetTick(); |
|
||||
} |
|
||||
} |
|
||||
osDelay(5); |
|
||||
} |
|
||||
} |
|
||||
void AppPeriodTaskMgr::startScheduler() { |
|
||||
osThreadDef(appPeriodTask, c_onappPeriodTaskThread, osPriorityNormal, 0, 1024); |
|
||||
appPeriodTaskId = osThreadCreate(osThread(appPeriodTask), NULL); |
|
||||
} |
|
@ -1,44 +0,0 @@ |
|||||
#pragma once
|
|
||||
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
|
|
||||
#include <functional>
|
|
||||
|
|
||||
#include "stm32basic/stm32basic.hpp"
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
//
|
|
||||
namespace iflytop { |
|
||||
|
|
||||
typedef void (*task_fn_t)(void*); |
|
||||
|
|
||||
typedef struct { |
|
||||
task_fn_t fn; |
|
||||
std::function<void()> exfn; |
|
||||
const char* taskname; |
|
||||
void* cxt; |
|
||||
int period; |
|
||||
int32_t lastcalltp; |
|
||||
} task_t; |
|
||||
|
|
||||
class AppPeriodTaskMgr { |
|
||||
private: |
|
||||
task_t task[20] = {0}; |
|
||||
int ntask = 0; |
|
||||
|
|
||||
public: |
|
||||
static AppPeriodTaskMgr* ins() { |
|
||||
static AppPeriodTaskMgr instance; |
|
||||
return &instance; |
|
||||
} |
|
||||
|
|
||||
void initialize(); |
|
||||
void regTask(const char* name, task_fn_t fn, void* cxt, int period); |
|
||||
void regTask(const char* name, std::function<void()> fn, int period); |
|
||||
void onThreadCB(); |
|
||||
void startScheduler(); |
|
||||
|
|
||||
// shceduler
|
|
||||
}; |
|
||||
|
|
||||
} // namespace iflytop
|
|
@ -1,2 +0,0 @@ |
|||||
#include "work_queue.hpp"
|
|
||||
|
|
@ -1,32 +0,0 @@ |
|||||
#pragma once
|
|
||||
#if 0
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
|
|
||||
#include <functional>
|
|
||||
|
|
||||
#include "cmsis_os.h"
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
//
|
|
||||
namespace iflytop { |
|
||||
using namespace std; |
|
||||
|
|
||||
typedef void(work_fn_t)(void*); |
|
||||
|
|
||||
typedef struct { |
|
||||
work_fn_t fn; |
|
||||
void* cxt; |
|
||||
} work_t; |
|
||||
|
|
||||
class WorkQueue { |
|
||||
private: |
|
||||
/* data */ |
|
||||
static osThreadId thread; |
|
||||
|
|
||||
public: |
|
||||
void initialize(); |
|
||||
void pushTask(void(fn)(void*), void* cxt); |
|
||||
}; |
|
||||
|
|
||||
} // namespace iflytop
|
|
||||
#endif
|
|
@ -1,37 +0,0 @@ |
|||||
#include "config_service.hpp"
|
|
||||
|
|
||||
|
|
||||
static config_t _config; |
|
||||
static config_t _default_val_config; |
|
||||
|
|
||||
#define TAG "config"
|
|
||||
static void dump_config(config_t *pcfg) { |
|
||||
ZLOGI(TAG, "=============== config ==============="); |
|
||||
ZLOGI(TAG, "configMark : %08x", pcfg->configMark); |
|
||||
ZLOGI(TAG, "placeHolder: %08x", pcfg->placeHolder); |
|
||||
ZLOGI(TAG, "="); |
|
||||
} |
|
||||
//static void create_default_config(config_t *default_cfg) { //
|
|
||||
// default_cfg->configMark = FLASH_MASK_VAL;
|
|
||||
// default_cfg->placeHolder = 0; // dhcp
|
|
||||
//}
|
|
||||
|
|
||||
void config_init(void) { |
|
||||
ZLOGI(TAG, "config_init"); |
|
||||
|
|
||||
_default_val_config.configMark = FLASH_MASK_VAL; |
|
||||
_default_val_config.placeHolder = 0; |
|
||||
|
|
||||
zflash_init((uint32_t *)&_config, sizeof(config_t) / 4); |
|
||||
zflash_set_default_data((uint32_t *)&_default_val_config); |
|
||||
|
|
||||
if (!zflash_check()) { |
|
||||
zflash_factory_reset(); |
|
||||
} |
|
||||
|
|
||||
dump_config(&_config); |
|
||||
} |
|
||||
config_t *config_get(void) { return &_config; } |
|
||||
void config_flush(void) { zflash_flush(); } |
|
||||
void config_factory_reset(void) { zflash_factory_reset(); } |
|
||||
|
|
@ -1,17 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include <stdint.h>
|
|
||||
|
|
||||
#include "stm32basic/stm32basic.hpp"
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
|
|
||||
typedef struct { |
|
||||
uint32_t configMark; |
|
||||
uint32_t placeHolder; |
|
||||
uint32_t checksum; //
|
|
||||
} config_t; |
|
||||
|
|
||||
void config_init(void); |
|
||||
config_t* config_get(void); |
|
||||
void config_flush(void); |
|
||||
void config_factory_reset(void); |
|
||||
|
|
@ -1,8 +0,0 @@ |
|||||
#include "device_info.hpp"
|
|
||||
|
|
||||
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
|
|
||||
|
|
||||
uint16_t deviceInfo_init() { return 0; } |
|
||||
uint16_t deviceInfo_getProtocolVersion() { return PROTOCOL_VERSION; } |
|
||||
uint16_t deviceInfo_getSoftwareVersion() { return SOFTWARE_VERSION; } |
|
||||
uint16_t deviceInfo_getHardwareVersion() { return HARDWARE_VERSION; } |
|
@ -1,17 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
|
|
||||
#include "project_configs.h"
|
|
||||
#include "base/config_service.hpp"
|
|
||||
|
|
||||
// uint16_t boardType;
|
|
||||
// uint16_t projectId;
|
|
||||
// uint16_t protcol_version;
|
|
||||
// uint16_t software_version;
|
|
||||
// uint16_t hardware_version;
|
|
||||
|
|
||||
uint16_t deviceInfo_init(); |
|
||||
uint16_t deviceInfo_getProtocolVersion(); |
|
||||
uint16_t deviceInfo_getSoftwareVersion(); |
|
||||
uint16_t deviceInfo_getHardwareVersion(); |
|
@ -1,21 +0,0 @@ |
|||||
#include "gflag.h" |
|
||||
|
|
||||
#include <stdbool.h> |
|
||||
#include <stdint.h> |
|
||||
|
|
||||
#include "cmsis_os.h" |
|
||||
|
|
||||
bool gInitErrorFlag = false; |
|
||||
uint32_t gBoardFlag = 0; |
|
||||
bool gEnableReportFlag = true; |
|
||||
|
|
||||
void gBoardFlagSetResetFlag() { |
|
||||
vPortEnterCritical(); |
|
||||
ZSET_BIT(gBoardFlag, 0); |
|
||||
vPortExitCritical(); |
|
||||
} |
|
||||
void gBoardFlagClearResetFlag() { |
|
||||
vPortEnterCritical(); |
|
||||
ZCLEAR_BIT(gBoardFlag, 0); |
|
||||
vPortExitCritical(); |
|
||||
} |
|
@ -1,27 +0,0 @@ |
|||||
|
|
||||
#ifndef ZGFLAG |
|
||||
#define ZGFLAG |
|
||||
#include <stdbool.h> |
|
||||
#include <stdint.h> |
|
||||
#ifdef __cplusplus |
|
||||
extern "C" { |
|
||||
#endif |
|
||||
|
|
||||
#define ZCLEAR_BIT(val, bit) (val &= ~(1 << bit)) |
|
||||
#define ZSET_BIT(val, bit) (val |= (1 << bit)) |
|
||||
|
|
||||
extern bool gInitErrorFlag; |
|
||||
/** |
|
||||
* bit: |
|
||||
* 0: board reset flag (1:reset) |
|
||||
*/ |
|
||||
extern uint32_t gBoardFlag; |
|
||||
extern bool gEnableReportFlag; |
|
||||
|
|
||||
void gBoardFlagSetResetFlag(); |
|
||||
void gBoardFlagClearResetFlag(); |
|
||||
|
|
||||
#ifdef __cplusplus |
|
||||
} |
|
||||
#endif |
|
||||
#endif |
|
@ -1,64 +0,0 @@ |
|||||
#include "protocol_processer_mgr.hpp"
|
|
||||
using namespace iflytop; |
|
||||
using namespace zscanprotocol; |
|
||||
using namespace transmit_disfection_protocol; |
|
||||
|
|
||||
#define TAG "ProtocolProcesserMgr"
|
|
||||
|
|
||||
static osThreadId PacketRxThreadId; |
|
||||
static void onPacketRxThreadStart(void const* argument) { |
|
||||
while (true) { |
|
||||
zcanbus_schedule(); |
|
||||
osDelay(3); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { //
|
|
||||
ProtocolProcesserMgr::ins()->onPacket(from, to, rawpacket, len); |
|
||||
} |
|
||||
|
|
||||
static void zcanbus_on_connected(bool connected) { |
|
||||
if (connected) { |
|
||||
ZLOGI(TAG, "connected to host"); |
|
||||
} else { |
|
||||
ZLOGI(TAG, "disconnected from host"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void ProtocolProcesserMgr::initialize() {} |
|
||||
void ProtocolProcesserMgr::startSchedule(int deviceId) { |
|
||||
|
|
||||
zcanbus_reglistener(zcanbus_on_rx); |
|
||||
zcanbus_reg_on_connected_listener(zcanbus_on_connected); |
|
||||
|
|
||||
osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); |
|
||||
PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); |
|
||||
} |
|
||||
|
|
||||
void ProtocolProcesserMgr::onPacket(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
||||
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
||||
|
|
||||
ProcessContext cxt; |
|
||||
cxt.packet = packet; |
|
||||
cxt.from = from; |
|
||||
cxt.to = to; |
|
||||
cxt.packetlen = len; |
|
||||
|
|
||||
bool processed = false; |
|
||||
|
|
||||
ZLOGI(TAG, "process packet from %d to %d, function_id %d, len %d", from, to, packet->function_id, len); |
|
||||
|
|
||||
for (auto& processer : cmdprocesser) { |
|
||||
if (processer.cmd == cxt.packet->function_id) { |
|
||||
processer.fn(&cxt); |
|
||||
processed = true; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if (!processed) { |
|
||||
ZLOGW(TAG, "no processer support this packet"); |
|
||||
zcanbus_send_errorack(packet, err::kerr_function_not_support); |
|
||||
} |
|
||||
ZLOGI(TAG, "process end"); |
|
||||
} |
|
@ -1,27 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include "protocol_processer_utils.hpp"
|
|
||||
|
|
||||
#define REG_FN(fn) ProtocolProcesserMgr::ins()->regCmdProcesser(CmdProcesser(k##fn, bind(&ThisClass::fn, this, placeholders::_1)))
|
|
||||
#define REG_LAMADA_FN(kfn, lamadafn) ProtocolProcesserMgr::ins()->regCmdProcesser(CmdProcesser(kfn, lamadafn))
|
|
||||
#define BIND_FN(ClassName, obj, fn) ProtocolProcesserMgr::ins()->regCmdProcesser(CmdProcesser(k##fn, bind(&ClassName::fn, obj, placeholders::_1)));
|
|
||||
namespace iflytop { |
|
||||
using namespace std; |
|
||||
|
|
||||
class ProtocolProcesserMgr { |
|
||||
list<CmdProcesser> cmdprocesser; |
|
||||
|
|
||||
public: |
|
||||
static ProtocolProcesserMgr* ins() { |
|
||||
static ProtocolProcesserMgr ins; |
|
||||
return &ins; |
|
||||
} |
|
||||
|
|
||||
void initialize(); |
|
||||
void startSchedule(int deviceId); |
|
||||
void regCmdProcesser(CmdProcesser processer) { cmdprocesser.push_back(processer); } |
|
||||
|
|
||||
public: |
|
||||
void onPacket(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len); |
|
||||
}; |
|
||||
|
|
||||
} // namespace iflytop
|
|
@ -1,51 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include <functional>
|
|
||||
#include <list>
|
|
||||
//
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
//
|
|
||||
#include "base/device_info.hpp"
|
|
||||
#include "gflag/gflag.h"
|
|
||||
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
|
|
||||
#include "stm32components/zcanreceiver/zcanreceiver.hpp"
|
|
||||
|
|
||||
namespace iflytop { |
|
||||
using namespace std; |
|
||||
using namespace zscanprotocol; |
|
||||
using namespace transmit_disfection_protocol; |
|
||||
|
|
||||
#define GET_PARAM(off) ((((int32_t*)(cxt->packet->params))[off]))
|
|
||||
#define PRAAM_LEN() ((cxt->packetlen - sizeof(zcanbus_packet_t)) / 4)
|
|
||||
|
|
||||
#define CHECK_PARAM_LEN(_paramNum, expectNum) \
|
|
||||
if (_paramNum != expectNum) { \ |
|
||||
zcanbus_send_errorack(cxt->packet, err::kerr_invalid_param_num); \ |
|
||||
return; \ |
|
||||
} |
|
||||
|
|
||||
/***********************************************************************************************************************
|
|
||||
* ClassDeclear * |
|
||||
***********************************************************************************************************************/ |
|
||||
class ProcessContext; |
|
||||
/***********************************************************************************************************************
|
|
||||
* TYPEDEF * |
|
||||
***********************************************************************************************************************/ |
|
||||
typedef function<void(ProcessContext* cxt)> cmdprocessfn_t; |
|
||||
/***********************************************************************************************************************
|
|
||||
* CLASS * |
|
||||
***********************************************************************************************************************/ |
|
||||
class ProcessContext { |
|
||||
public: |
|
||||
uint8_t from; |
|
||||
uint8_t to; |
|
||||
zcanbus_packet_t* packet; |
|
||||
size_t packetlen; |
|
||||
}; |
|
||||
class CmdProcesser { |
|
||||
public: |
|
||||
int cmd; |
|
||||
cmdprocessfn_t fn; |
|
||||
CmdProcesser(int cmd, cmdprocessfn_t fn) : cmd(cmd), fn(fn) {} |
|
||||
}; |
|
||||
|
|
||||
} // namespace iflytop
|
|
@ -1,49 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
|
|
||||
#include "stm32basic/stm32basic.hpp"
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
|
|
||||
namespace iflytop { |
|
||||
|
|
||||
class HalUtils { |
|
||||
public: |
|
||||
static void uartdmainit(UART_HandleTypeDef* uart, DMA_HandleTypeDef* rxdma, uint32_t rxdmach, DMA_HandleTypeDef* txdma, uint32_t txdmach) { |
|
||||
rxdma->Instance = getDmaStreamTypeDef(rxdma); |
|
||||
rxdma->Init.Channel = rxdmach; |
|
||||
rxdma->Init.Direction = DMA_PERIPH_TO_MEMORY; |
|
||||
rxdma->Init.PeriphInc = DMA_PINC_DISABLE; |
|
||||
rxdma->Init.MemInc = DMA_MINC_ENABLE; |
|
||||
rxdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
|
||||
rxdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
|
||||
rxdma->Init.Mode = DMA_NORMAL; |
|
||||
rxdma->Init.Priority = DMA_PRIORITY_LOW; |
|
||||
rxdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
|
||||
ZASSERT(rxdma->Instance); |
|
||||
if (HAL_DMA_Init(rxdma) != HAL_OK) { |
|
||||
Error_Handler(); |
|
||||
} |
|
||||
|
|
||||
__HAL_LINKDMA(uart, hdmarx, *rxdma); |
|
||||
|
|
||||
txdma->Instance = getDmaStreamTypeDef(txdma); |
|
||||
txdma->Init.Channel = txdmach; |
|
||||
txdma->Init.Direction = DMA_MEMORY_TO_PERIPH; |
|
||||
txdma->Init.PeriphInc = DMA_PINC_DISABLE; |
|
||||
txdma->Init.MemInc = DMA_MINC_ENABLE; |
|
||||
txdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
|
||||
txdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
|
||||
txdma->Init.Mode = DMA_NORMAL; |
|
||||
txdma->Init.Priority = DMA_PRIORITY_LOW; |
|
||||
txdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
|
||||
ZASSERT(rxdma->Instance); |
|
||||
if (HAL_DMA_Init(txdma) != HAL_OK) { |
|
||||
Error_Handler(); |
|
||||
} |
|
||||
|
|
||||
__HAL_LINKDMA(uart, hdmatx, *txdma); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
} // namespace iflytop
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue