14 Commits
28 changed files with 4850 additions and 2859 deletions
+3 -3
View File
@@ -6,10 +6,10 @@ TARGET_PROJ ?= node
ifeq ($(TARGET_PROJ), node)
BUILD_DIR := $(PROJECT)/build/node
CONFIG_FILE := $(PROJECT)/config/node.json
else ifeq ($(TARGET_PROJ), ge)
else ifeq ($(TARGET_PROJ), ground)
XILINX_VITIS_CLASSIC := y
BUILD_DIR := $(PROJECT)/build/ge
CONFIG_FILE := $(PROJECT)/config/ge.json
BUILD_DIR := $(PROJECT)/build/ground
CONFIG_FILE := $(PROJECT)/config/ground.json
else
$(error Unsupported target PROJECT: $(TARGET_PROJ))
endif
+5 -4
View File
@@ -1,7 +1,7 @@
{
"project_name": "hsjl_ground",
"version": "0.0.0",
"hw_design": "hw/hsjl_ground_v0.0.1.xsa",
"version": "0.1.0",
"hw_design": "hw/hsjl_ground_v0.1.0.xsa",
"apps": {
"datalink": {
"sources": ["src/*"],
@@ -13,11 +13,12 @@
"stack_size": "0x20000"
},
"build_config": {
"debug": {
"release": {
"include-path": ["src/include"],
"libraries": ["m"]
},
"release": {
"debug": {
"include-path": ["src/include"],
"libraries": ["m"]
}
+4 -4
View File
@@ -1,7 +1,7 @@
{
"project_name": "hsjl_node",
"version": "0.0.0",
"hw_design": "hw/hsjl_node_v0.0.1.hdf",
"version": "0.1.0",
"hw_design": "hw/hsjl_node_v0.1.0.hdf",
"apps": {
"datalink": {
"sources": ["src/*"],
@@ -13,11 +13,11 @@
"stack_size": "0x20000"
},
"build_config": {
"debug": {
"release": {
"include-path": ["src/include"],
"libraries": ["m"]
},
"release": {
"debug": {
"include-path": ["src/include"],
"libraries": ["m"]
}
+18 -15
View File
@@ -1,7 +1,7 @@
# HSJL 上位机串口通信协议
> 版本:v1.2
> 日期:2025 年 6 月 12 日
> 日期:2025 年 6 月 16 日
---
@@ -46,19 +46,19 @@ block-beta
| 字段名 | 字节数 (Byte) | 说明 |
|--|--|--|
| 帧头 | 2 | 固定值:`0x54 0x5A` |
| 帧头 | 2 | 固定值:`0x5A 0x54` |
| 数据段 | ≤950 | 业务数据内容 |
| Dummy Byte | 1 | 固定填充:`0x00` |
| 校验和 | 1 | 所有**数据段**字节累加和(无符号累加) |
| 数据段长度 | 2 | 数据段字节数(不含 Dummy/校验/帧尾) |
| 帧尾 | 2 | 固定值:`0xFE 0x5A` |
| 帧尾 | 2 | 固定值:`0x5A 0xFE` |
### 帧内冲突规避规则
为防止数据段中出现帧尾 `0xFE 0x5A`:
为防止数据段中出现帧尾 `0x5A 0xFE`:
- 若数据段中出现 `0xFE 0x5A`,需插入 `0x00` 变成 `0x00 0xFE 0x5A`
- 接收端收到 `0x00 0xFE 0x5A` 还原为 `0xFE 0x5A`
- 若数据段中出现 `0x5A 0xFE`,需插入 `0x00` 变成 `0x00 0x5A 0xFE`
- 接收端收到 `0x00 0x5A 0xFE` 还原为 `0x5A 0xFE`
### 帧长说明
@@ -192,13 +192,13 @@ block-beta
### (可选)遥测指令
遥测指令上传的 Payload 由 5 部分组成,顺序存储,共 188 字节:
遥测指令上传的 Payload 由 5 部分组成,顺序存储,共 200 字节:
| 字段名 | 字节数 (Byte) |
| ------------ | ------------- |
| 时间戳 | 8 |
| 总线日志 | 16 |
| 链路层日志 | 88 |
| 链路层日志 | 100 |
| 物理层日志 | 56 |
| 硬件状态日志 | 20 |
@@ -219,7 +219,7 @@ block-beta
#### 链路层日志
链路层日志顺序存储,共 88字节:
链路层日志顺序存储,共 100 字节:
| 字段名 | 字节数 (Byte) | 说明 |
| -------------------- | ------------- | ---------------------------------------- |
@@ -239,12 +239,15 @@ block-beta
| 分发帧发送计数器 | 4 | 每发送一次分发帧,计数器+1(仅簇首) |
| 分发帧接收计数器 | 4 | 每配置接收一次分发帧,计数器+1(仅成员) |
| 分发帧接收正确计数器 | 4 | 每正确接收一次分发帧,计数器+1(仅成员) |
| 网关帧发送计数器 | 4 | 每发送一次网关帧,计数器+1 |
| 网关帧接收计数器 | 4 | 每配置接收一次网关帧,计数器+1 |
| 网关帧接收正确计数器 | 4 | 每正确接收一次网关帧,计数器+1 |
| RTT帧发送计数器 | 4 | 每发送一次RTT帧,计数器+1 |
| RTT帧接收计数器 | 4 | 每配置接收一次RTT帧,计数器+1 |
| RTT帧接收正确计数器 | 4 | 每正确接收一次RTT帧,计数器+1 |
| 网管帧发送计数器 | 4 | 每发送一次网管帧,计数器+1 |
| 网管帧接收计数器 | 4 | 每配置接收一次网管帧,计数器+1 |
| 网管帧接收正确计数器 | 4 | 每正确接收一次网管帧,计数器+1 |
| RTT帧发送计数器 | 4 | 每发送一次 RTT 帧,计数器+1 |
| RTT帧接收计数器 | 4 | 每配置接收一次 RTT 帧,计数器+1 |
| RTT帧接收正确计数器 | 4 | 每正确接收一次 RTT 帧,计数器+1 |
| 业务帧发送计数器 | 4 | 每发送一次业务帧,计数器+1 |
| 业务帧接收计数器 | 4 | 每配置接收一次业务帧,计数器+1 |
| 业务帧接收正确计数器 | 4 | 每正确接收一次业务帧,计数器+1 |
| 时间偏移量记录 | 4, int32 | 记录上一次节点时间和帧同步时间的偏差 |
| 发送数据ID记录 | 4 | 记录上一次发送数据的ID |
| 接收数据ID记录 | 4 | 记录上一次接收数据的ID |
+455
View File
@@ -0,0 +1,455 @@
'''
@brief This is an example plugin, can receive and send data
@author
@date
@license LGPL-3.0
'''
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QTextEdit, QPushButton, QLabel, QScrollArea, QSplitter
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QFont, QTextCursor
from struct import Struct
try:
import utils_ui
from plugins.base import Plugin_Base
from conn import ConnectionStatus
from i18n import _
from widgets import statusBar
except ImportError:
from COMTool import utils_ui
from COMTool.plugins.base import Plugin_Base
from COMTool.i18n import _
from COMTool.conn import ConnectionStatus
from COMTool.widgets import statusBar
class Plugin(Plugin_Base):
id = "HJ DATALINK"
name = _("HJ DATALINK")
showReceiveDataSignal = pyqtSignal(str)
def onInit(self, config):
'''
init params
'''
default = {
"version": 1,
"customSendItems": [
{
"caption": "自检",
"icon": "fa5.question-circle",
"data": "5A 54 E1 EE 00 CF 02 5A FE"
},
{
"caption": "数据发送测试 - 40 Byte",
"icon": "fa5.play-circle",
"data": (
"5A 54 E4 EE 00 00 00 00 02 00 28 "
"00 01 02 03 04 05 06 07 "
"08 09 0A 0B 0C 0D 0E 0F "
"10 11 12 13 14 15 16 17 "
"18 19 1A 1B 1C 1D 1E 1F "
"20 21 22 23 24 25 26 27 "
"00 08 31 5A FE"
)
},
# {
# "caption": "数据发送测试 - 2",
# "icon": "fa5.play-circle",
# "data": ""
# },
{
"caption": "装订 - 【主 - 0x01】128 kbps,时隙表 0",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 01 22 00 00 9E 06 5A FE"
},
{
"caption": "装订 - 【主 - 0x01】512 kbps,时隙表 1",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 01 33 01 00 B0 06 5A FE"
},
{
"caption": "装订 - 【主 - 0x01】2 Mbps,时隙表 2",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 01 44 02 00 C2 06 5A FE"
},
{
"caption": "装订 - 【主 - 0x01】静默",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE 55 01 22 00 00 49 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x02】128 kbps,时隙表 0",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 02 22 00 00 9F 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x02】512 kbps,时隙表 1",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 02 33 01 00 B1 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x02】2M bps,时隙表 2",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 02 44 02 00 C3 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x02】静默",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE 55 02 22 00 00 4A 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x03】128 kbps,时隙表 0",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 03 22 00 00 A0 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x03】512 kbps,时隙表 1",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 03 33 01 00 B2 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x03】2 Mbps,时隙表 2",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE AA 03 44 02 00 C4 06 5A FE"
},
{
"caption": "装订 - 【从 - 0x03】静默",
"icon": "fa5.play-circle",
"data": "5A 54 E3 EE 55 03 22 00 00 4B 06 5A FE"
},
{
"caption": "遥测",
"icon": "fa5.play-circle",
"data": "5A 54 E6 EE 00 D4 02 5A FE"
},
]
}
self.config = config
for k in default:
if not k in self.config:
self.config[k] = default[k]
def onConnChanged(self, status:ConnectionStatus, msg:str):
print("-- connection changed: {}, msg: {}".format(status, msg))
def onWidgetMain(self, parent):
'''
main widget, just return a QWidget object
'''
self.mainWidget = QSplitter(Qt.Vertical)
# receive widget
self.receiveWidget = QTextEdit("")
font = QFont('Consolas, DejaVu Sans Mono, Courier New, monospace, Microsoft YaHei', 10)
self.receiveWidget.setFont(font)
self.receiveWidget.setLineWrapMode(QTextEdit.NoWrap)
# clear button
self.clearBtn = QPushButton("")
utils_ui.setButtonIcon(self.clearBtn, "mdi6.broom")
# send scroll
self.customSendScroll = QScrollArea()
self.customSendScroll.setMinimumHeight(20)
self.customSendScroll.setWidgetResizable(True)
self.customSendScroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.customSendScroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
cutomSendItemsWraper = QWidget()
self.customSendScroll.setWidget(cutomSendItemsWraper)
# -- wrapper widget
cutomSendItemsWraper0 = QWidget()
cutomSendItemsWraper0.setProperty("class", "scrollbar2")
layout0 = QVBoxLayout()
layout0.setContentsMargins(0,8,0,0)
cutomSendItemsWraper0.setLayout(layout0)
layout0.addWidget(self.customSendScroll)
customSendItemsLayoutWrapper = QVBoxLayout()
customSendItemsLayoutWrapper.setContentsMargins(0,0,0,0)
cutomSendItemsWraper.setLayout(customSendItemsLayoutWrapper)
# -- items container
self.customItems = QWidget()
self.customSendItemsLayout = QVBoxLayout()
self.customSendItemsLayout.setContentsMargins(0,0,0,0)
self.customItems.setLayout(self.customSendItemsLayout)
customSendItemsLayoutWrapper.addWidget(self.customItems)
customSendItemsLayoutWrapper.addStretch(0)
# add widgets
self.mainWidget.addWidget(self.receiveWidget)
self.mainWidget.addWidget(self.clearBtn)
self.mainWidget.addWidget(cutomSendItemsWraper0)
self.mainWidget.setStretchFactor(0, 2)
self.mainWidget.setStretchFactor(1, 1)
self.mainWidget.setStretchFactor(2, 11)
# event
def clearReceived():
self.receiveWidget.clear();self.statusBar.clear()
self.clearBtn.clicked.connect(clearReceived)
return self.mainWidget
def onWidgetStatusBar(self, parent):
self.statusBar = statusBar(rxTxCount=True)
return self.statusBar
def onUiInitDone(self):
'''
UI init done, you can update your widget here
this method runs in UI thread, do not block too long
'''
newItems = []
print(self.config["customSendItems"])
for item in self.config["customSendItems"]:
print(item)
item = self.insertSendItem(item, load=True)
newItems.append(item)
self.config["customSendItems"] = newItems
self.showReceiveDataSignal.connect(self.showReceivedData)
# frame struct
self.structSelfTestRsp = Struct("<BB B BBBbbb HHHBBbB B 3s")
self.structStatusCheckRsp = Struct("<BB Q IIII IBBBBIB III III III III III III i II 3s IIII d Q dBB dB H B 2s BBBbbb HHHBBbB B 3s")
self.structData = Struct("<BB IBH 40s")
self.structSysInfo = Struct("<IHI H B I B fff fff fff")
def insertSendItem(self, item = None, load = False):
caption = item["caption"]
itemWidget = QWidget()
layout = QHBoxLayout()
layout.setContentsMargins(0,0,0,0)
itemWidget.setLayout(layout)
send = QPushButton("")
label = QLabel(caption)
if (not "icon" in item) or not item["icon"]:
item["icon"] = "fa.send"
utils_ui.setButtonIcon(send, item["icon"])
send.setProperty("class", "smallBtn")
def sendCustomData(idx):
self.sendCustomItem(self.config["customSendItems"][idx])
send.clicked.connect(lambda: sendCustomData(self.customSendItemsLayout.indexOf(itemWidget)))
layout.addWidget(label)
layout.addWidget(send)
self.customSendItemsLayout.addWidget(itemWidget)
if not load:
self.config["customSendItems"].append(item)
return item
def showReceivedData(self, text: str):
curScrollValue = self.receiveWidget.verticalScrollBar().value()
self.receiveWidget.moveCursor(QTextCursor.End)
endScrollValue = self.receiveWidget.verticalScrollBar().value()
self.receiveWidget.insertPlainText(text)
if curScrollValue < endScrollValue:
self.receiveWidget.verticalScrollBar().setValue(curScrollValue)
else:
self.receiveWidget.moveCursor(QTextCursor.End)
def onReceived(self, data : bytes):
'''
call in receive thread, not UI thread
'''
self.statusBar.addRx(len(data))
## Apply data validation check
if len(data) < 7:
self.showReceiveDataSignal.emit("\n### Wrong data format: wrong frame header/tail\n")
return
dataLen = data[-3]
if data[0] != 0x5A or data[1] != 0x54 or data[-1] != 0xFE or data[-2] != 0x5A:
self.showReceiveDataSignal.emit("\n### Wrong data format: wrong length\n")
checkSum = 0
for i in data[2:-4]:
checkSum += i
if checkSum & 0xFF != data[-4]:
self.showReceiveDataSignal.emit("\n### Wrong data format: wrong check sum\n")
## Eval data
data = data[2:-5].replace(b'\x00\x54\xFE', b'\x54\xFE')
# self.printFrame(data)
if data[0] == 0xE1:
# eval self test
self.showReceiveDataSignal.emit(self.evalSelfTestRsp(data) + "\n")
elif data[0] == 0xE6:
self.showReceiveDataSignal.emit(self.evalStatusCheckRsp(data) + "\n")
elif data[0] == 0xE5:
self.showReceiveDataSignal.emit('Retrieved Data Frame:\n' + self.printFrame(data) + "\n")
else:
self.showReceiveDataSignal.emit(f"\n### Unexpected response code 0x{data[0]:02x}.\n")
def evalSelfTestRsp(self, data: bytes):
try:
payload = self.structSelfTestRsp.unpack(data)
except :
return f"\n### evalSelfTestRsp:: Failed to unpack data (data length {len(data)} byte).\n"
ret = "----------- 自检回令 -----------\n"
ret += f"节点编号: 0x{payload[-2]:02X}\n"
ret += "节点类型: "
if payload[1] == 0xEE:
ret += f"C频段 (0x{payload[1]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[1]:02X})\n"
ret += "自检结果: "
if payload[2] == 0xAA:
ret += f"正常 (0x{payload[2]:02X})\n"
elif payload[2] == 0x55:
ret += f"异常 (0x{payload[2]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[2]:02X})\n"
hwOffset = 3
ret += f"FPGA 电压监测: {bin(payload[hwOffset+0])[2:].zfill(8)}\n"
ret += f"时钟锁定状态: {bin(payload[hwOffset+1])[2:].zfill(8)}\n"
ret += f"AD 锁定状态: {bin(payload[hwOffset+2])[2:].zfill(8)}\n"
ret += f"AD 温度 1: {payload[hwOffset+3]:>4d}\n"
ret += f"AD 温度 2: {payload[hwOffset+4]:>4d}\n"
ret += f"FPGA 温度: {payload[hwOffset+5]:>4d}\n"
ret += f"天线-1 工作 PLL: {(payload[hwOffset+6] >> 15) & 0x01:>1d}\n"
ret += f"天线-1 工作频率: {(payload[hwOffset+6] & 0x7FFF)+3700:>4d}\n"
ret += f"天线-2 工作 PLL: {(payload[hwOffset+7] >> 15) & 0x01:>1d}\n"
ret += f"天线-2 工作频率: {(payload[hwOffset+7] & 0x7FFF)+3700:>4d}\n"
ret += f"天线-3 工作 PLL: {(payload[hwOffset+8] >> 15) & 0x01:>1d}\n"
ret += f"天线-3 工作频率: {(payload[hwOffset+8] & 0x7FFF)+3700:>4d}\n"
ret += f"天线 PLL 锁定状态: {bin(payload[hwOffset+9])[2:].zfill(8)}\n"
ret += f"天线工作模式: {bin(payload[hwOffset+10])[2:].zfill(8)}\n"
ret += f"天线温度: {payload[hwOffset+11]:>4d}\n"
ret += "--------------------------------\n"
return ret + '\n' + self.printFrame(data)
def printFrame(self, data: bytes):
ret = ''
for i in range(len(data)):
ret += f'{data[i]:02X}'
ret += '\n' if i%16 == 15 else ' '
ret += '\n'
return ret
def evalStatusCheckRsp(self, data: bytes):
try:
payload = self.structStatusCheckRsp.unpack(data)
except :
return f"\n### evalStatusCheckRsp:: Failed to unpack data (data length {len(data)} byte).\n"
ret = "----------- 遥测回令 -----------\n"
ret += "节点类型: "
if payload[1] == 0xEE:
ret += f"C频段 (0x{payload[1]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[1]:02X})\n"
ret += f"时间戳: {payload[2]/1e5:.2f} ms\n"
sysbusOffset = 3
linkOffset = 7
phyOffset = 36
hwOffset = 50
ret += "\n -- 总线状态\n"
ret += f"配置装订: {payload[sysbusOffset + 0]:08X}\n"
ret += f"接收数据计数: {payload[sysbusOffset + 1]:>6d}\n"
ret += f"发送数据计数: {payload[sysbusOffset + 2]:>6d}\n"
ret += f"遥测请求计数: {payload[sysbusOffset + 3]:>6d}\n"
ret += "\n -- 链路层状态\n"
ret += f"时元号: {payload[linkOffset + 0]:>6d}\n"
ret += f"时隙号: {payload[linkOffset + 1]:>3d}\n"
ret += "当前角色: "
if payload[linkOffset + 2] == 0xAA:
ret += f"簇首 (0x{payload[linkOffset + 2]:02X})\n"
elif payload[linkOffset + 2] == 0xCC:
ret += f"成员 (0x{payload[linkOffset + 2]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[linkOffset + 2]:02X})\n"
ret += "网络连接状态: "
if payload[linkOffset + 3] == 0x11:
ret += f"已连接 (0x{payload[linkOffset + 3]:02X})\n"
elif payload[linkOffset + 3] == 0x00:
ret += f"未连接 (0x{payload[linkOffset + 3]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[linkOffset + 3]:02X})\n"
ret += "网络运行阶段: "
if payload[linkOffset + 4] == 0x11:
ret += f"建网阶段 (0x{payload[linkOffset + 4]:02X})\n"
elif payload[linkOffset + 4] == 0x22:
ret += f"业务通信 (0x{payload[linkOffset + 4]:02X})\n"
else:
ret += f"【未知错误】(0x{payload[linkOffset + 4]:02X})\n"
ret += f"重建/入网计数: {payload[linkOffset + 5]:>6d}\n"
ret += f"通信天线位号: {payload[linkOffset + 6]:>1d}\n"
ret += f"建网帧发送计数: {payload[linkOffset + 7]:>6d}\n"
ret += f"建网帧接收计数: {payload[linkOffset + 8]:>6d}\n"
ret += f"建网帧正确计数: {payload[linkOffset + 9]:>6d}\n"
ret += f"应答帧发送计数: {payload[linkOffset + 10]:>6d}\n"
ret += f"应答帧接收计数: {payload[linkOffset + 11]:>6d}\n"
ret += f"应答帧正确计数: {payload[linkOffset + 12]:>6d}\n"
ret += f"分发帧发送计数: {payload[linkOffset + 13]:>6d}\n"
ret += f"分发帧接收计数: {payload[linkOffset + 14]:>6d}\n"
ret += f"分发帧正确计数: {payload[linkOffset + 15]:>6d}\n"
ret += f"网管帧发送计数: {payload[linkOffset + 16]:>6d}\n"
ret += f"网管帧接收计数: {payload[linkOffset + 17]:>6d}\n"
ret += f"网管帧正确计数: {payload[linkOffset + 18]:>6d}\n"
ret += f"RTT 帧发送计数: {payload[linkOffset + 19]:>6d}\n"
ret += f"RTT 帧接收计数: {payload[linkOffset + 20]:>6d}\n"
ret += f"RTT 帧正确计数: {payload[linkOffset + 21]:>6d}\n"
ret += f"业务帧发送计数: {payload[linkOffset + 22]:>6d}\n"
ret += f"业务帧接收计数: {payload[linkOffset + 23]:>6d}\n"
ret += f"业务帧正确计数: {payload[linkOffset + 24]:>6d}\n"
ret += f"时间偏差记录: {payload[linkOffset + 25]/1e2:.2f} us\n"
ret += f"发送数据 ID: {payload[linkOffset + 26]:>6d}\n"
ret += f"接收数据 ID: {payload[linkOffset + 27]:>6d}\n"
ret += "\n -- 物理层状态\n"
ret += f"捕获计数: {payload[phyOffset + 0]:>6d}\n"
ret += f"帧同步计数: {payload[phyOffset + 1]:>6d}\n"
ret += f"译码计数: {payload[phyOffset + 2]:>6d}\n"
ret += f"CRC 正确计数:{payload[phyOffset + 3]:>6d}\n"
ret += f"多普勒估计: {payload[phyOffset + 4]:.2f} Hz\n"
ret += f"正确接收时刻: {payload[phyOffset + 5]/1e2:.2f} us\n"
ret += f"捕获峰均比: {payload[phyOffset + 6]:.2f}\n"
ret += f"捕获相位值: {payload[phyOffset + 7]:>3d}\n"
ret += f"捕获频偏通道: {payload[phyOffset + 8]:>3d}\n"
ret += f"帧同步峰均比: {payload[phyOffset + 9]:.2f}\n"
ret += f"帧同步频偏通道: {payload[phyOffset + 10]:>3d}\n"
ret += f"交织输入数据幅度统计:\t0x{payload[phyOffset + 11]:04X}\n"
ret += f"天线控制模式: {bin(payload[phyOffset + 12])[2:].zfill(8)}\n"
ret += "\n -- 硬件状态\n"
ret += f"FPGA 电压监测: {bin(payload[hwOffset+0])[2:].zfill(8)}\n"
ret += f"时钟锁定状态: {bin(payload[hwOffset+1])[2:].zfill(8)}\n"
ret += f"AD 锁定状态: {bin(payload[hwOffset+2])[2:].zfill(8)}\n"
ret += f"AD 温度 1: {payload[hwOffset+3]:>4d}\n"
ret += f"AD 温度 2: {payload[hwOffset+4]:>4d}\n"
ret += f"FPGA 温度: {payload[hwOffset+5]:>4d}\n"
ret += f"天线-1 工作 PLL: {(payload[hwOffset+6] >> 15) & 0x01:>1d}\n"
ret += f"天线-1 工作频率: {(payload[hwOffset+6] & 0x7FFF)+3700:>4d}\n"
ret += f"天线-2 工作 PLL: {(payload[hwOffset+7] >> 15) & 0x01:>1d}\n"
ret += f"天线-2 工作频率: {(payload[hwOffset+7] & 0x7FFF)+3700:>4d}\n"
ret += f"天线-3 工作 PLL: {(payload[hwOffset+8] >> 15) & 0x01:>1d}\n"
ret += f"天线-3 工作频率: {(payload[hwOffset+8] & 0x7FFF)+3700:>4d}\n"
ret += f"天线 PLL 锁定状态: {bin(payload[hwOffset+9])[2:].zfill(8)}\n"
ret += f"天线工作模式: {bin(payload[hwOffset+10])[2:].zfill(8)}\n"
ret += f"天线温度: {payload[hwOffset+11]:>4d}\n"
ret += "--------------------------------\n"
return ret + '\n' + self.printFrame(data)
def onSent(self, ok, msg, length, path):
if ok:
self.statusBar.addTx(length)
else:
self.hintSignal.emit("error", _("Error"), _("Send data failed!") + " " + msg)
def sendCustomItem(self, item):
data = item["data"]
dateBytes = self.parseSendData(data, encoding = self.configGlobal["encoding"], isHexStr = True)
if dateBytes:
self.send(dateBytes, callback=self.onSent)
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
+1 -1
Submodule scripts updated: 00960b6b8f...d13f6cb8b3
+4 -4
View File
@@ -103,13 +103,13 @@ static ad9528outputSettings_t clockOutputSettings = {
},
.outChannelDiv = {
5,25,25,5,5,
5,5,8,5,5,
5,5,10,5
5,5,5,5,5,
5,5,8,5
},
.outFrequency_Hz = {
200e6, 40e6, 40e6, 200e6, 200e6,
200e6, 200e6, 125e6, 200e6, 200e6,
200e6, 200e6, 100e6, 200e6
200e6, 200e6, 200e6, 200e6, 200e6,
200e6, 200e6, 125e6, 200e6
}
};
+1 -1
View File
@@ -25,10 +25,10 @@
#include "common.h"
#include "error.h"
#include "delay.h"
#include "system_monitor.h"
#include "hwconfig.h"
#include "config/app_config.h"
#include "dev_profile/dev_profile.h"
#include "systembus/systembus.h"
#ifdef RFSOC
#include "xrfdc.h"
#endif
+1 -2
View File
@@ -28,7 +28,6 @@
#include "error.h"
#include "timer.h"
#include "hwconfig.h"
#include "system_monitor.h"
#include "config/app_config.h"
#include "dev_profile/dev_profile.h"
#include "systembus/systembus.h"
@@ -220,7 +219,7 @@ int32_t SetupInterruptSystem(struct irq_ctrl_desc *descPtr)
return Status;
}
/* Initialize linklayer layer interrupt. */
/* Initialize linklayer layer interrupt. */
Status = irq_trigger_level_set(descPtr, PERIODIC_5MS_INTR_ID, IRQ_EDGE_RISING);
if (Status != SUCCESS)
{
+4 -4
View File
@@ -883,14 +883,14 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
// Reset scan net FMS for next scan process.
L2_Scan_Reset(instPtr->scanFSM);
UpdateMainSate(instPtr, L2_INIT_STATE);
instPtr->rtneConfig.rtneTable = initTable;
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
// instPtr->rtneConfig.rtneTable = initTable;
// instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
}
else if (instPtr->nextState == L2_NORMAL_STATE)
{
UpdateMainSate(instPtr, L2_NORMAL_STATE);
instPtr->rtneConfig.rtneTable = normalTable0;
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(normalTable0);
// instPtr->rtneConfig.rtneTable = normalTable0;
// instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(normalTable0);
}
else
{
+1 -1
View File
@@ -27,7 +27,7 @@
#include "msg_def.h"
#include "circ_queue.h"
#include "../phy_layer/phy_layer.h"
#include "../../system_monitor.h"
#include "../../systembus/systembus.h"
/************************** Constant Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
#define AssertL2Event(instPtr, event) (Linklayer_EventHandler((instPtr), (event)))
File diff suppressed because it is too large Load Diff
+15 -7
View File
@@ -243,12 +243,20 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
// Get data payload & upload
SYSMON_SVC_PAYLOAD recvPayload;
recvPayload.dataId = message->dataId;
recvPayload.nodeId = message->common.src;
recvPayload.dataLen = message->dataLen;
memcpy(recvPayload.data, message->data, maxDataLen);
SysMonitor_GenRecvRsp(&recvPayload);
if (message->dataId != DATA_ID_NONE)
{
if (message->dataLen > maxDataLen)
{
DBG_ERROR("Payload length" PRIu16 " out of range.\n", message->dataLen);
return EIGNORE;
}
SYSBUS_SVC_PLD *recvPayload = calloc(1, sizeof(SYSBUS_SVC_PLD));
recvPayload->dataId = message->dataId;
recvPayload->nodeId = message->common.src;
recvPayload->dataLen = message->dataLen;
memcpy(recvPayload->data, message->data, message->dataLen);
SysMonitor_GenRecvRsp(recvPayload);
}
// Logging...
instPtr->log.rxLog.dataId = message->dataId;
@@ -318,7 +326,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
}
// Get data payload & upload
SYSMON_SVC_PAYLOAD recvPayload;
SYSBUS_SVC_PLD recvPayload;
recvPayload.dataId = message->dataId;
recvPayload.nodeId = message->common.src;
recvPayload.dataLen = message->dataLen;
+109 -43
View File
@@ -196,16 +196,29 @@ static int32_t Service_Packing128K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
message->srcSpeedY = instPtr->sysInfo.vY;
message->srcSpeedZ = instPtr->sysInfo.vZ;
// TODO: Packing extra payload
// Pack extra payload
if (type == L2_FRAME_SVC)
{
SYSMON_SVC_PAYLOAD sendPayload;
// Packing extra payload
SYSBUS_SVC_PLD *sendPayload;
SysMonitor_GetSendPayload(&sendPayload);
message->common.dst = sendPayload.nodeId;
message->dataId = sendPayload.dataId;
message->dataLen = sendPayload.dataLen;;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload.data, sendPayload.dataLen);
if(sendPayload == NULL)
{
message->common.dst = L2_NONE_ID;
message->dataId = DATA_ID_NONE;
message->dataLen = 0;
memset(message->data, 0xAA, maxDataLen);
}
else
{
// message->common.dst = sendPayload->nodeId;
message->dataId = sendPayload->dataId;
message->dataLen = sendPayload->dataLen;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload->data, (sendPayload->dataLen > maxDataLen) ?
maxDataLen : sendPayload->dataLen);
free(sendPayload);
}
}
else
{
@@ -264,14 +277,26 @@ static int32_t Service_Packing512K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
message->srcSpeedY = instPtr->sysInfo.vY;
message->srcSpeedZ = instPtr->sysInfo.vZ;
// TODO: Packing extra payload
SYSMON_SVC_PAYLOAD sendPayload;
// Pack extra payload
SYSBUS_SVC_PLD *sendPayload;
SysMonitor_GetSendPayload(&sendPayload);
message->common.dst = sendPayload.nodeId;
message->dataId = sendPayload.dataId;
message->dataLen = sendPayload.dataLen;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload.data, sendPayload.dataLen);
if(sendPayload == NULL)
{
message->common.dst = L2_NONE_ID;
message->dataId = DATA_ID_NONE;
message->dataLen = 0;
memset(message->data, 0xAA, maxDataLen);
}
else
{
// message->common.dst = sendPayload->nodeId;
message->dataId = sendPayload->dataId;
message->dataLen = sendPayload->dataLen;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload->data, (sendPayload->dataLen > maxDataLen) ?
maxDataLen : sendPayload->dataLen);
free(sendPayload);
}
// Append CRC
uint32_t crcVal;
@@ -322,14 +347,26 @@ static int32_t Service_Packing2M(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t d
message->srcSpeedY = instPtr->sysInfo.vY;
message->srcSpeedZ = instPtr->sysInfo.vZ;
// TODO: Packing extra payload
SYSMON_SVC_PAYLOAD sendPayload;
// Packing extra payload
SYSBUS_SVC_PLD *sendPayload;
SysMonitor_GetSendPayload(&sendPayload);
message->common.dst = sendPayload.nodeId;
message->dataId = sendPayload.dataId;
message->dataLen = sendPayload.dataLen;;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload.data, sendPayload.dataLen);
if(sendPayload == NULL)
{
message->common.dst = L2_NONE_ID;
message->dataId = DATA_ID_NONE;
message->dataLen = 0;
memset(message->data, 0xAA, maxDataLen);
}
else
{
// message->common.dst = sendPayload->nodeId;
message->dataId = sendPayload->dataId;
message->dataLen = sendPayload->dataLen;
memset(message->data, 0xAA, maxDataLen);
memcpy(message->data, sendPayload->data, (sendPayload->dataLen > maxDataLen) ?
maxDataLen : sendPayload->dataLen);
free(sendPayload);
}
// Append CRC
uint32_t crcVal;
@@ -491,12 +528,20 @@ static int32_t Service_PktHandler128K(L2_INST *instPtr, uint8_t *msg)
}
// Get data payload
SYSMON_SVC_PAYLOAD recvPayload;
recvPayload.dataId = message->dataId;
recvPayload.nodeId = message->common.src;
recvPayload.dataLen = message->dataLen;
memcpy(recvPayload.data, message->data, maxDataLen);
SysMonitor_GenRecvRsp(&recvPayload);
if (message->dataId != DATA_ID_NONE)
{
if (message->dataLen > maxDataLen)
{
DBG_ERROR("Payload length" PRIu16 " out of range.\n", message->dataLen);
return EIGNORE;
}
SYSBUS_SVC_PLD *recvPayload = calloc(1, sizeof(SYSBUS_SVC_PLD));
recvPayload->dataId = message->dataId;
recvPayload->nodeId = message->common.src;
recvPayload->dataLen = message->dataLen;
memcpy(recvPayload->data, message->data, message->dataLen);
SysMonitor_GenRecvRsp(recvPayload);
}
// Logging...
instPtr->log.rxLog.dataId = message->dataId;
@@ -571,12 +616,20 @@ static int32_t Service_PktHandler512K(L2_INST *instPtr, uint8_t *msg)
}
// Get data payload
SYSMON_SVC_PAYLOAD recvPayload;
recvPayload.dataId = message->dataId;
recvPayload.nodeId = message->common.src;
recvPayload.dataLen = message->dataLen;
memcpy(recvPayload.data, message->data, maxDataLen);
SysMonitor_GenRecvRsp(&recvPayload);
if (message->dataId != DATA_ID_NONE)
{
if (message->dataLen > maxDataLen)
{
DBG_ERROR("Payload length" PRIu16 " out of range.\n", message->dataLen);
return EIGNORE;
}
SYSBUS_SVC_PLD *recvPayload = calloc(1, sizeof(SYSBUS_SVC_PLD));
recvPayload->dataId = message->dataId;
recvPayload->nodeId = message->common.src;
recvPayload->dataLen = message->dataLen;
memcpy(recvPayload->data, message->data, message->dataLen);
SysMonitor_GenRecvRsp(recvPayload);
}
// Logging...
instPtr->log.rxLog.dataId = message->dataId;
@@ -651,12 +704,20 @@ static int32_t Service_PktHandler2M(L2_INST *instPtr, uint8_t *msg)
}
// Get data payload
SYSMON_SVC_PAYLOAD recvPayload;
recvPayload.dataId = message->dataId;
recvPayload.nodeId = message->common.src;
recvPayload.dataLen = message->dataLen;
memcpy(recvPayload.data, message->data, message->dataLen);
SysMonitor_GenRecvRsp(&recvPayload);
if (message->dataId != DATA_ID_NONE)
{
if (message->dataLen > maxDataLen)
{
DBG_ERROR("Payload length" PRIu16 " out of range.\n", message->dataLen);
return EIGNORE;
}
SYSBUS_SVC_PLD *recvPayload = calloc(1, sizeof(SYSBUS_SVC_PLD));
recvPayload->dataId = message->dataId;
recvPayload->nodeId = message->common.src;
recvPayload->dataLen = message->dataLen;
memcpy(recvPayload->data, message->data, message->dataLen);
SysMonitor_GenRecvRsp(recvPayload);
}
// Logging...
instPtr->log.rxLog.dataId = message->dataId;
@@ -887,10 +948,9 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
memcpy(instPtr->sendPktData, testData, msgLen);
#endif
}
else
else if (rtneEntry->dst == L2_GetNodeId(instPtr))
{
// In services slots, rx mode is always enabled when other nodes are transmitting
commNode = L2_GetNodeById(instPtr->nodeList, L2_HEAD_ID);
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
// antenna selection based on node list
antIndex = commNode->nodeInfo.antIndex;
// member node receives message in advertise slot
@@ -898,7 +958,13 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
svcFSMPtr->rxCnt++;
}
(void)Phy_SetAntIndex(phyRef, antIndex);
else
{
// otherwise suspend
antIndex = PHY_ANT_INDEX_NONE;
torState = L2_TOR_SUSPEND;
}
(void)Phy_SetAntIndex(instPtr->config.phyInstPtr, antIndex);
(void)L2_SetupNextSlot(instPtr, torState, L2_FRAME_SVC);
break;
default:
+216 -156
View File
@@ -63,180 +63,240 @@ const uint16_t freqTable[L1_FRAME_MAX_HOPS] =
};
//const uint8_t antCalTable[L1_ANT_NUM][L1_FRAME_MAX_HOPS][L1_ANT_CH_NUM] =
////Antenna-JG01
//{
// // Antenna-1
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
// // Antenna-2
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
// // Antenna-3
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
//};
// const uint8_t antCalTable[L1_ANT_NUM][L1_FRAME_MAX_HOPS][L1_ANT_CH_NUM] =
// //Antenna-JG01
// {
// // Antenna-1
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
// // Antenna-2
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
// // Antenna-3
// {
// { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
// { 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
// { 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
// { 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
// { 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
// { 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
// { 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
// { 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
// { 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
// { 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
// { 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
// { 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
// { 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
// { 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
// { 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
// { 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
// { 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
// { 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
// { 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
// { 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
// { 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
// { 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
// { 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
// { 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
// { 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
// { 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
// { 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
// { 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
// { 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
// { 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
// { 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
// { 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
// { 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
// { 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
// { 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
// { 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
// { 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
// { 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
// { 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
// { 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
// { 0, 1767, -7775, -8328},
// },
// };
const uint8_t hopPattern_ADV_24MS[L1_FRAME_ADV_24MS_HOPS] =
{
0U, 35U, 66U, 47U, 40U, 16U, 30U, 65U,
43U, 7U, 70U, 63U, 7U, 65U, 42U, 28U,
2U
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16U,
};
const uint8_t hopPattern_ACK_8MS[L1_FRAME_ACK_8MS_HOPS] =
{
0U, 5U, 49U, 25U, 7U
10U, 11U, 12U, 13U, 14U,
};
//const uint8_t hopPattern_128KBPS_4MS[L1_FRAME_128KBPS_4MS_HOPS] =
//{
// 80U, 16U, 17U, 65U, 60U, 54U, 31U, 15U,
// 6U, 19U, 79U, 52U, 29U, 42U, 23U, 59U,
// 60U, 58U, 76U, 67U, 31U, 76U, 77U, 79U,
// 79U, 14U, 61U, 5U, 71U, 50U, 32U, 77U,
// 60U,
//};
//const uint8_t hopPattern_128KBPS_4MS[L1_FRAME_128KBPS_4MS_HOPS] =
//{
// 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
// 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
// 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U,
// 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U,
// 32U,
//};
const uint8_t hopPattern_128KBPS_4MS[L1_FRAME_128KBPS_4MS_HOPS] =
{
80U, 16U, 17U, 65U, 60U, 54U, 31U, 15U,
6U, 19U, 79U, 52U, 29U, 42U, 23U, 59U,
60U, 58U, 76U, 67U, 31U, 76U, 77U, 79U,
79U, 14U, 61U, 5U, 71U, 50U, 32U, 77U,
60U,
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
10U, 11U, 10U, 11U, 10U, 11U, 10U, 11U,
10U, 12U, 10U, 12U, 10U, 12U, 10U, 12U,
10U, 13U, 10U, 13U, 10U, 13U, 10U, 13U,
10U,
};
//const uint8_t hopPattern_128KBPS_4MS[L1_FRAME_128KBPS_4MS_HOPS] =
//{
// 0U, 1U, 2U, 3U, 4U, 5U, 6U,
//};
//const uint8_t hopPattern_128KBPS_4MS[L1_FRAME_128KBPS_4MS_HOPS] =
//{
// 0U, 16U, 17U, 65U, 60U, 54U, 31U, 15U,
// 6U, 19U, 39U, 52U, 29U, 42U, 23U, 49U,
// 33U, 58U, 24U, 67U, 31U, 13U, 17U, 10U,
// 59U, 14U, 61U, 5U, 41U, 44U, 32U, 35U,
// 60U,
//};
//const uint8_t hopPattern_512KBPS_4MS[L1_FRAME_512KBPS_4MS_HOPS] =
//{
// 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
// 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U,
// 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U,
// 32U, 33U, 34U, 35U, 36U, 37U, 38U, 39U,
// 40U, 41U, 42U, 43U,
//};
const uint8_t hopPattern_512KBPS_4MS[L1_FRAME_512KBPS_4MS_HOPS] =
{
80U, 62U, 40U, 66U, 65U, 33U, 55U, 33U,
57U, 11U, 37U, 45U, 5U, 69U, 77U, 54U,
37U, 63U, 14U, 64U, 76U, 31U, 45U, 52U,
40U, 20U, 20U, 32U, 0U, 60U, 23U, 19U,
15U, 38U, 62U, 18U,
8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16U, 17U, 16U, 17U, 16U, 17U, 16U, 17U,
16U, 18U, 16U, 18U, 16U, 18U, 16U, 18U,
16U, 19U, 16U, 19U, 16U, 19U, 16U, 19U,
16U, 20U, 16U, 20U,
};
//const uint8_t hopPattern_2MBPS_4MS[L1_FRAME_2MBPS_4MS_HOPS] =
//{
// 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U,
// 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U,
// 32U, 33U, 34U, 35U, 36U, 37U, 38U, 39U,
// 40U, 41U, 42U, 43U, 44U, 45U, 46U, 47U,
// 48U, 49U, 50U, 51U, 52U, 53U,
//};
//const uint8_t hopPattern_2MBPS_4MS[L1_FRAME_2MBPS_4MS_HOPS] =
//{
// 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U,
// 24U, 25U, 24U, 25U, 24U, 25U, 24U, 25U,
// 24U, 26U, 24U, 26U, 24U, 26U, 24U, 26U,
// 24U, 27U, 24U, 27U, 24U, 27U, 24U, 27U,
// 24U, 28U, 24U, 28U, 24U, 28U,
//};
const uint8_t hopPattern_2MBPS_4MS[L1_FRAME_2MBPS_4MS_HOPS] =
{
0U, 13U, 37U, 44U, 16U, 0U, 59U, 50U,
69U, 70U, 58U, 14U, 9U, 72U, 27U, 25U,
21U, 76U, 20U, 35U, 30U, 58U, 22U, 59U,
48U, 33U, 8U, 7U, 41U, 12U, 44U, 79U,
77U, 38U, 76U, 75U, 48U, 56U,
16U, 17U, 18U, 19U, 20U, 21U, 20U, 20U,
20U, 20U, 20U, 20U, 20U, 20U, 20U, 20U,
20U, 20U, 20U, 20U, 20U, 20U, 20U, 20U,
20U, 20U, 20U, 20U, 20U, 20U, 20U, 20U,
20U, 20U, 20U, 20U, 20U, 20U,
};
/** @} PhysicalLayer_AntennaConfig_Constants*/
@@ -402,7 +462,7 @@ int32_t Phy_SetAntIndex(PHY_INST *instPtr, PHY_ANT_INDEX antIndex)
{
ASSERT(instPtr != NULL);
if (antIndex < 0 || antIndex >= L1_ANT_NUM)
if (antIndex < PHY_ANT_INDEX_NONE || antIndex > PHY_ANT_INDEX_3)
{
DBG_ERROR("Antenna index out of range: %" PRIu8 ". \n", antIndex);
return EPARAM;
+1 -1
View File
@@ -31,7 +31,7 @@
#include "xadcps.h"
#endif
#endif
#include "../../system_monitor.h"
#include "../../systembus/systembus.h"
#include "../../time_ctrl/time_ctrl.h"
/************************** Constant Definitions *****************************/
/**
-380
View File
@@ -1,380 +0,0 @@
/**
* @addtogroup SystemMonitor
* @{
*/
/***************************** Include Files *********************************/
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "common.h"
#include "circ_queue.h"
#include "system_monitor.h"
#include "systembus/systembus.h"
/************************** Constant Definitions *****************************/
/**
* @name SystemMonitor_Private_Constants
* @{
*/
#define BUFF_A 0x00
#define BUFF_B 0x01
#define BUFF_NONE 0xFF
#define SYSINFO_PACK_LEN 54 // bytes
#define PAYLOAD_PACK_LEN 46 // bytes
#define SLOTLOG_PACK_LEN 88 // bytes
#define PRTCLLOG_PACK_ELN 24 // bytes
#define HWSTATE_PACK_ELN 12 // bytes
/** @} SystemMonitor_Private_Constants*/
/************************** Data Type Definitions ****************************/
/**
* @struct PINGPONG
* @brief PingPing Control
*/
typedef struct
{
uint8_t latest; ///< latest available index
uint8_t rBusy; ///< current read busy index
uint8_t wBusy; ///< current write busy index
} PINGPONG;
/**
* @struct SYSMONITOR
* @brief System Monitor struct holds all the system log info
*/
typedef struct
{
SYSMON_CONFIG config; ///< system monitor initialization parameters
CIRC_QUEUE *sendQueue; ///< send queue
CIRC_QUEUE *recvQueue; ///< receive queue
PINGPONG sysInfoCtrl;
SYSINFO sysInfo[2];
PINGPONG linkLogCtrl;
LINKLOG linkLog[2];
PINGPONG phyLogCtrl;
PHYLOG phyLog[2];
PINGPONG hwStateCtrl;
HWSTATE hwState[2];
} SYSMONITOR;
/************************** Function Prototypes ******************************/
static uint8_t GetWritable(PINGPONG ctrllor);
static uint8_t GetReadable(PINGPONG ctrllor);
/************************** Variable Definitions *****************************/
static SYSMONITOR *sysMonitorInst;
extern SYSBUS *sysbusDescPtr;
/*********************** Function Implementations ***************************/
inline static uint8_t GetWritable(PINGPONG ctrllor)
{
// Allow only one write.
ASSERT(ctrllor.wBusy == BUFF_NONE);
if (ctrllor.rBusy == BUFF_NONE)
return ((ctrllor.latest == BUFF_B) ? BUFF_A : BUFF_B);
else
return ((ctrllor.rBusy == BUFF_B) ? BUFF_A : BUFF_B);
}
inline static uint8_t GetReadable(PINGPONG ctrllor)
{
if (ctrllor.wBusy == BUFF_NONE || ctrllor.wBusy != ctrllor.latest)
return ((ctrllor.latest == BUFF_NONE) ? BUFF_A : BUFF_B);
else
return ((ctrllor.wBusy == BUFF_B) ? BUFF_A : BUFF_B);
}
/**
* @brief Initialize System monitor
*
* @return SUCCESS
*/
int32_t SysMonitor_Init(SYSMON_CONFIG *config)
{
ASSERT(config != NULL);
sysMonitorInst = calloc(1, sizeof(SYSMONITOR));
if (sysMonitorInst == NULL)
{
return ENOMEM;
}
memcpy(&(sysMonitorInst->config), config, sizeof(SYSMON_CONFIG));
sysMonitorInst->sendQueue = NULL;
sysMonitorInst->recvQueue = NULL;
memset(&(sysMonitorInst->sysInfoCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->linkLogCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->phyLogCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->hwStateCtrl), BUFF_NONE, sizeof(PINGPONG));
if (CircQueueCreate(&(sysMonitorInst->sendQueue),
sysMonitorInst->config.sendQueueMax) == false)
{
SysMonitor_Destroy();
return ENOMEM;
}
if (CircQueueCreate(&(sysMonitorInst->recvQueue),
sysMonitorInst->config.recvQueueMax) == false)
{
SysMonitor_Destroy();
return ENOMEM;
}
return SUCCESS;
}
/**
* @brief Destroy system monitor release all allocated memory
*/
void SysMonitor_Destroy(void)
{
free(sysMonitorInst);
}
/**
* @name SystemInfo_API
* @{
*/
/**
* @brief Update system info.
*
* @param info
*/
void SysMonitor_UpdateSysinfo(const SYSINFO *info)
{
ASSERT(info != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->sysInfoCtrl);
sysMonitorInst->sysInfoCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->sysInfo[buffIndx]), info, sizeof(SYSINFO));
sysMonitorInst->sysInfoCtrl.latest = buffIndx;
sysMonitorInst->sysInfoCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get system info.
*
* @param info
*/
void SysMonitor_GetSysinfo(SYSINFO *info)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(info != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->sysInfoCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->sysInfoCtrl);
sysMonitorInst->sysInfoCtrl.rBusy = buffIndx;
memcpy(info, &(sysMonitorInst->sysInfo[buffIndx]), sizeof(SYSINFO));
sysMonitorInst->sysInfoCtrl.rBusy = buffIndex_old;
}
/** @} SystemInfo_API*/
/**
* @name ServicePayload_API
* @{
*/
/**
* @brief Update send payload by
*
* @param payload
*/
int32_t SysMonitor_UpdateSendPayload(SYSMON_SVC_PAYLOAD *payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(payload != NULL);
// validity check
if (payload->dataLen > PAYLOAD_LEN_MAX)
{
DBG_ERROR("Payload length %d exceeds valid range.", payload->dataLen);
return EPARAM;
}
// push message into send queue
if (CircQueuePush(sysMonitorInst->sendQueue, (void *)payload) == false)
{
DBG_WARNING("SystemMonitor::SEND Queue overflowed!\n");
return EQUEUE;
}
return SUCCESS;
}
/**
* @brief Get the latest send payload.
*
* @param payload
*/
void SysMonitor_GetSendPayload(SYSMON_SVC_PAYLOAD *payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(payload != NULL);
if (CircQueuePop(sysMonitorInst->sendQueue, (void *)payload) == false)
{
payload->dataId = DATA_ID_NONE;
payload->nodeId = 0;
payload->dataLen = 0;
// set payload to be 0xAA to balanced average signal power
memset(payload->data, 0xAA, PAYLOAD_LEN_MAX);
DBG_WARNING("SystemMonitor::Nothing to be sent.\n");
}
}
/**
* @brief Update receive payload.
*
* @param payload
*/
int32_t SysMonitor_GenRecvRsp(SYSMON_SVC_PAYLOAD *payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(sysbusDescPtr != NULL);
int32_t Status;
if (payload->dataId == DATA_ID_NONE || payload->dataLen > PAYLOAD_LEN_MAX)
{
return EIGNORE;
}
Status = SystemBus_GenRecvRsp(sysbusDescPtr, payload);
return Status;
}
/** @} ServicePayload_API*/
/**
* @name Linklayer_Log_API
* @{
*/
/**
* @brief Update link layer log
*
* @param log
*/
void SysMonitor_UpdateLinklayerLog(const LINKLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->linkLogCtrl);
sysMonitorInst->linkLogCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->linkLog[buffIndx]), log, sizeof(LINKLOG));
sysMonitorInst->linkLogCtrl.latest = buffIndx;
sysMonitorInst->linkLogCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest link layer log
*
* @param log
*/
void SysMonitor_GetLinklayerLog(LINKLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->linkLogCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->linkLogCtrl);
sysMonitorInst->linkLogCtrl.rBusy = buffIndx;
memcpy(log, &(sysMonitorInst->linkLog[buffIndx]), sizeof(LINKLOG));
sysMonitorInst->linkLogCtrl.rBusy = buffIndex_old;
}
/** @} Linklayer_Log_API*/
/**
* @name PhysicalLayer_Log_API
* @{
*/
/**
* @brief Update physical layer log
*
* @param log
*/
void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->phyLogCtrl);
sysMonitorInst->phyLogCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->phyLog[buffIndx]), log, sizeof(PHYLOG));
sysMonitorInst->phyLogCtrl.latest = buffIndx;
sysMonitorInst->phyLogCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest physical layer log
*
* @param log
*/
void SysMonitor_GetPhysicalLayerLog(PHYLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->phyLogCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->phyLogCtrl);
sysMonitorInst->phyLogCtrl.rBusy = buffIndx;
memcpy(log, &(sysMonitorInst->phyLog[buffIndx]), sizeof(PHYLOG));
sysMonitorInst->phyLogCtrl.rBusy = buffIndex_old;
}
/** @} */
/**
* @name HardwareState_Log_API
* @{
*/
/**
* @brief Log hardware running status.
*
* @param state
*/
void SysMonitor_UpdateHardwareStatus(const HWSTATE *state)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(state != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->hwStateCtrl);
sysMonitorInst->hwStateCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->hwState[buffIndx]), state, sizeof(HWSTATE));
sysMonitorInst->hwStateCtrl.latest = buffIndx;
sysMonitorInst->hwStateCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest hardware running status.
*
* @param state
*/
void SysMonitor_GetHardwareStatus(HWSTATE *state)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(state != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->hwStateCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->hwStateCtrl);
sysMonitorInst->hwStateCtrl.rBusy = buffIndx;
memcpy(state, &(sysMonitorInst->hwState[buffIndx]), sizeof(HWSTATE));
sysMonitorInst->hwStateCtrl.rBusy = buffIndex_old;
}
/** @} HardwareState_Log_API */
/** @} SystemMonitor*/
-258
View File
@@ -1,258 +0,0 @@
/**
* @defgroup SystemMonitor
* @{
*/
#ifndef __SYSTEM_MONITOR_H_
#define __SYSTEM_MONITOR_H_
/***************************** Include Files *********************************/
#include <stdint.h>
#include <stdbool.h>
#include "util.h"
/************************* Constant Definitions ******************************/
/**
* @name SystemMonitor_Constants
* @{
*/
#define PAYLOAD_LEN_MAX 1000
#define DATA_ID_NONE UINT32_MAX
#define DATA_ID_TEST 0x02030203
#define VOLTAGE_LSB 0.01 // volt
#define VOLTAGE_MAX 2.55 // volt
#define VOLT_PS_STD 1.0
#define VOLT_PSAUX_STD 1.8
#define VOLT_DDR_STD 1.5
#define VOLT_PL_STD 1.0
#define VOLT_PLAUX_STD 1.8
#define VOLT_BRAM_STD 1.0
#define VOLT_PS_OK BIT(0)
#define VOLT_PSAUX_OK BIT(1)
#define VOLT_DDR_OK BIT(2)
#define VOLT_PL_OK BIT(3)
#define VOLT_PLAUX_OK BIT(4)
#define VOLT_BRAM_OK BIT(5)
#define VOLT_ANT_PROC_OK BIT(0)
#define VOLT_ANT_RF_OK BIT(2)
#define VOLT_ANT_NIL_OK BIT(4)
#define ANT_STATE_OK BIT(6)
// Xilinx Recommended
// #define IS_PS_VALID(x) (x <= 1.05 && x >= 0.95)
// #define IS_PSAUX_VALID(x) (x <= 1.89 && x >= 1.71)
// #define IS_DDR_VALID(x) (x <= 1.89 && x >= 1.14)
// #define IS_PL_VALID(x) (x <= 1.03 && x >= 0.97)
// #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71)
// #define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97)
#define IS_PS_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define IS_PSAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_DDR_VALID(x) ((x) <= 1.7 && (x) >= 1.3)
#define IS_PL_VALID(x) (x <= 1.1 && (x) >= 0.9)
#define IS_PLAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_BRAM_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define CLK_SP_PLL1_LOCK BIT(0)
#define CLK_SP_PLL2_LOCK BIT(2)
#define CLK_AD0_BBPLL_LOCK BIT(0)
#define CLK_AD0_RFPLL_LOCK BIT(2)
#define CLK_AD1_BBPLL_LOCK BIT(4)
#define CLK_AD1_RFPLL_LOCK BIT(6)
#define CLK_ANT_BBPLL_LOCK BIT(0)
#define CLK_ANT_RFPLL1_LOCK BIT(2)
#define CLK_ANT_RFPLL2_LOCK BIT(4)
#define TEMPERATURE_LSB 1.0 // Celsius degree
#define TEMPERATURE_MAX 127.0 // Celsius degree
#define TEMPERATURE_MIN -128.0 // Celsius degree
/** @} SystemMonitor_Constants */
/************************* Data Type Definitions ****************************/
/**
* @struct SYSINFO
* @brief System Infomation log
*/
typedef struct __attribute__((packed))
{
uint32_t psBDS; ///< -- unit: ms, 0~604799999
uint16_t pBDS; ///< -- unit: week, 0~0~8191
uint32_t psGPS; ///< -- unit: ms, 0~604799999
uint16_t pGPS; ///< -- unit: week, 0~0~8191
uint8_t tmInd; ///< Time validation indicator \n
// -- [0] GPS\n
// -- [1] reserve.\n
// -- [2] UTC\n
// -- [3] BDS\n
float tmFly; ///< Time of flying uint: s
uint8_t stFly; ///< Status of flying \n
// [7:6] departure status 11 - departed/00 - not departed \n
// [5:4] ready status 11 - ready/00 - not ready \n
// [3:2] attitude status 11 - attitude ok/00 - attitude not ok \n
// [1:0] attitude adjust status 11 - adjusted/00 - not adjusted
float posX; ///< coord X Position in launch coordinate system
float posY; ///< coord Y Position in launch coordinate system
float posZ; ///< coord Z Position in launch coordinate system
float vX; ///< Speed X in launch coordinate system
float vY; ///< Speed Y in launch coordinate system
float vZ; ///< Speed Z in launch coordinate system
float pitch; ///< Pitch Attitude in launch inertia coordinate system
float yaw; ///< Yaw Attitude in launch inertia coordinate system
float roll; ///< Roll Attitude in launch inertia coordinate system
} SYSINFO;
/**
* @struct SYSBUSLOG
* @brief System Info holds the system bus log
*/
typedef struct __attribute__((packed))
{
// SystemBus log
uint8_t lastConfig[4]; ///< Last valid config \n
// byte 0: Enable control, 0xAA - enable, 0x55 - disable \n
// byte 1: Node ID \n
// byte 2: Service rate \n
// byte 3: routing table number
uint32_t recvCnt; ///< number of received data packet
uint32_t sendCnt; ///< number of send data packet
uint32_t remoteCnt; ///< number of remote check commands
} SYSBUSLOG;
/**
* @struct LINKLOG
* @brief Linklayer Log struct holds the Linklayer log
*/
typedef struct __attribute__((packed))
{
// Network log
uint32_t tuNum; ///< current time unite number
uint8_t slotNum; ///< current slot number
uint8_t nodeType; ///< current node type
uint8_t cxnStatus; ///< current connection status
uint8_t linkStage; ///< current linklayer working stage
uint32_t recxnCnt; ///< reconnect trial count
uint8_t antIndex; ///< current working antenna index
uint32_t advTxCnt; ///< adv frame send count
uint32_t advRecvCnt; ///< adv frame received count
uint32_t advCorrectCnt; ///< adv frame received correctly count
uint32_t ackTxCnt; ///< ack frame send count
uint32_t ackRecvCnt; ///< ack frame received count
uint32_t ackCorrectCnt; ///< ack frame received correctly count
uint32_t disTxCnt; ///< dist frame send count
uint32_t disRecvCnt; ///< dist frame received count
uint32_t disCorrectCnt;///< dist frame received correctly count
uint32_t mngTxCnt; ///< mng frame send count
uint32_t mngRecvCnt; ///< mng frame received count
uint32_t mngCorrectCnt; ///< mng frame received correctly count
uint32_t rttTxCnt; ///< rtt frame send count
uint32_t rttRecvCnt; ///< rtt frame received count
uint32_t rttCorrectCnt; ///< rtt frame received correctly count
uint32_t svcTxCnt; ///< svc frame send count
uint32_t svcRecvCnt; ///< svc frame received count
uint32_t svcCorrectCnt; ///< svc frame received correctly count
int32_t timeDev; ///< last time deviation result
uint32_t sendId; ///< last send data id
uint32_t recvId; ///< last received data id
uint8_t reserve[3]; ///< reserved data
} LINKLOG;
/**
* @struct PHYLOG
* @brief Physical Layer Log struct holds the Linklayer log
*/
typedef struct __attribute__((packed))
{
uint32_t acqCnt; ///< acquisition count
uint32_t fsyncCnt; ///< frame sync count
uint32_t decodeCnt; ///< decode count
uint32_t crcCnt; ///< crc valid count
double doppler; ///< last doppler estimation result
uint64_t recvStamp; ///< last frame arrival time
double acqPAPR; ///< last acquisition peak-average ration
uint8_t acqPhase; ///< last acquisition phase estimation
uint8_t acqFreqCh; ///< last acquisition frequency deviation estimation
double fsyncPAPR; ///< last frame sync peak-average ration
uint8_t fsyncFreqCh; ///< last frame sync frequency estimation
uint16_t deintlvAmpEst; ///< de-interleave amplitude estimation
uint8_t antControl; ///< current antenna rf mode
uint8_t reserve[2]; ///< reserved data
} PHYLOG;
/**
* @struct HWSTATE
* @brief Hardware Status Log struct holds all hardware status
*/
typedef struct __attribute__((packed))
{
bool isSpOk; ///< signal processor state
bool isAntOk; ///< antenna state
// -- Signal processor status
uint8_t spFpgaVolt; ///< Signal processor voltage state indicator
uint8_t spClkState; ///< Signal processor clock state indicator
uint8_t spAdLockState; ///< Signal processor adc lock state indicator
int8_t spAdTemp_0; ///< Signal processor adc0 temperature
int8_t spAdTemp_1; ///< Signal processor adc1 temperature
int8_t spFpgaTemp; ///< Signal processor FPGA temperature
// -- Antenna status
uint16_t ant1Freq; ///< Antenna 1 frequency
uint16_t ant2Freq; ///< Antenna 2 frequency
uint16_t ant3Freq; ///< Antenna 3 frequency
uint8_t antPll; ///< Antenna pll lock state indicator
uint8_t antMode; ///< Antenna mode indicator
int8_t antTemp; ///< Antenna rf temperature
uint8_t antRsvd; ///< Antenna reserved status register
uint8_t phyId;
uint8_t reserve[3];
} HWSTATE;
/**
* @struct SYSMON_CONFIG
* @brief System monitor config struct holds system monitor initialization parameters
*/
typedef struct
{
uint32_t sendQueueMax; ///< maximum send queue length
uint32_t recvQueueMax; ///< maximum receive queue length
} SYSMON_CONFIG;
/**
* @struct SYSMON_SVC_PAYLOAD
* @brief Payload struct that holds the service payload
*/
typedef struct
{
uint32_t dataId; ///< data identifier
uint8_t nodeId; ///< destination ID for tx, source ID for rx
uint16_t dataLen; ///< data length
uint8_t data[PAYLOAD_LEN_MAX];
} SYSMON_SVC_PAYLOAD;
/************************** Function Prototypes ******************************/
int32_t SysMonitor_Init(SYSMON_CONFIG *config);
void SysMonitor_Destroy(void);
void SysMonitor_UpdateSysinfo(const SYSINFO *info);
void SysMonitor_GetSysinfo(SYSINFO *info);
int32_t SysMonitor_UpdateSendPayload(SYSMON_SVC_PAYLOAD *payload);
void SysMonitor_GetSendPayload(SYSMON_SVC_PAYLOAD *payload);
int32_t SysMonitor_GenRecvRsp(SYSMON_SVC_PAYLOAD *payload);
void SysMonitor_UpdateLinklayerLog(const LINKLOG *log);
void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log);
void SysMonitor_UpdateHardwareStatus(const HWSTATE *state);
void SysMonitor_GetLinklayerLog(LINKLOG *log);
void SysMonitor_GetPhysicalLayerLog(PHYLOG *log);
void SysMonitor_GetHardwareStatus(HWSTATE *state);
#endif //__SYSTEM_MONITOR_H_
/** @} */
+373 -14
View File
@@ -27,7 +27,6 @@
#include "common.h"
#include "error.h"
#include "circ_queue.h"
#include "../system_monitor.h"
/**
* @addtogroup SystemBus_Protocol_Routine
@@ -71,8 +70,8 @@
// -- Request
// -- -- Enable control
#define WD_EN_CMD 0x02
#define EN_CMD_ENABLE 0x66
#define EN_CMD_SILENT 0x88
#define EN_CMD_ENABLE 0xAA
#define EN_CMD_SILENT 0x55
// -- -- Node mode control
#define WD_ID_CMD 0x03
// -- -- Service Rate control
@@ -128,7 +127,7 @@
// -- Request
// -- -- --
// -- Response
#define RM_TEST_RSP_LEN 190
#define RM_TEST_RSP_LEN 202
// -- -- 8 byte time stamp
#define RT_TIME_STAMP_OFFSET 0x02
#define RT_TIME_STAMP_LEN 8
@@ -137,18 +136,59 @@
#define RT_SYSBUS_LOG_LEN 16
// -- -- 88 byte link layer log
#define RT_LINK_LOG_OFFSET 0x1A
#define RT_LINK_LOG_LEN 88
#define RT_LINK_LOG_LEN 100
// -- -- 56 byte physical layer log
#define RT_PHY_LOG_OFFSET 0x72
#define RT_PHY_LOG_OFFSET 0x7E
#define RT_PHY_LOG_LEN 56
// -- -- 20 byte hardware log
#define RT_HARDWARE_ST_OFFSET 0xAA
#define RT_HARDWARE_ST_OFFSET 0xB6
#define RT_HARDWARE_ST_LEN 20
// My Production Type
#define MY_PRD_ID PRD_DL_C
/** @} SystemBus_MSG_Constants*/
#define BUFF_A 0x00
#define BUFF_B 0x01
#define BUFF_NONE 0xFF
#define SYSINFO_PACK_LEN 54 // bytes
#define PAYLOAD_PACK_LEN 46 // bytes
#define SLOTLOG_PACK_LEN 88 // bytes
#define PRTCLLOG_PACK_ELN 24 // bytes
#define HWSTATE_PACK_ELN 12 // bytes
/************************** Data Type Definitions ****************************/
/**
* @struct PINGPONG
* @brief PingPing Control
*/
typedef struct
{
uint8_t latest; ///< latest available index
uint8_t rBusy; ///< current read busy index
uint8_t wBusy; ///< current write busy index
} PINGPONG;
/**
* @struct SYSMONITOR
* @brief System Monitor struct holds all the system log info
*/
typedef struct
{
SYSMON_CONFIG config; ///< system monitor initialization parameters
CIRC_QUEUE *sendQueue; ///< send queue
CIRC_QUEUE *recvQueue; ///< receive queue
PINGPONG sysInfoCtrl;
SYSINFO sysInfo[2];
PINGPONG linkLogCtrl;
LINKLOG linkLog[2];
PINGPONG phyLogCtrl;
PHYLOG phyLog[2];
PINGPONG hwStateCtrl;
HWSTATE hwState[2];
} SYSMONITOR;
/************************** Function Prototypes ******************************/
static uint8_t GetWritable(PINGPONG ctrllor);
static uint8_t GetReadable(PINGPONG ctrllor);
static int32_t SystemBus_GenSelfTestRsp(SYSBUS *instPtr);
static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg);
static int32_t SystemBus_Echo(SYSBUS *instPtr, SYSBUS_UART_FRAME *frame);
@@ -160,6 +200,26 @@ static int32_t SystemBus_GenRemoteTestRsp(SYSBUS *instPtr, uint8_t *msg);
#include "../networking/phy_layer/phy_layer.h"
extern L2_INST *linkInstPtr;
extern L2_CONFIG linkConfig;
extern SYSBUS *sysbusDescPtr;
static SYSMONITOR *sysMonitorInst;
inline static uint8_t GetWritable(PINGPONG ctrllor)
{
// Allow only one write.
ASSERT(ctrllor.wBusy == BUFF_NONE);
if (ctrllor.rBusy == BUFF_NONE)
return ((ctrllor.latest == BUFF_B) ? BUFF_A : BUFF_B);
else
return ((ctrllor.rBusy == BUFF_B) ? BUFF_A : BUFF_B);
}
inline static uint8_t GetReadable(PINGPONG ctrllor)
{
if (ctrllor.wBusy == BUFF_NONE || ctrllor.wBusy != ctrllor.latest)
return ((ctrllor.latest == BUFF_NONE) ? BUFF_A : BUFF_B);
else
return ((ctrllor.wBusy == BUFF_B) ? BUFF_A : BUFF_B);
}
inline bool SystemBus_IsReqPending(SYSBUS *instPtr)
{
@@ -178,6 +238,7 @@ inline bool SystemBus_IsTxBusy(SYSBUS *instPtr)
ASSERT(instPtr != NULL);
return (!instPtr->isTxDone);
}
inline bool SystemBus_IsRxBusy(SYSBUS *instPtr)
{
ASSERT(instPtr != NULL);
@@ -237,7 +298,7 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
if (msg[WD_ID_CMD] >= 0 && msg[WD_ID_CMD] < linkConfig.netScale)
{
reconfig |= (msg[WD_ID_CMD] != linkConfig.myId);
linkConfig.myType = (msg[WD_ID_CMD] == 0) ? L2_NODE_HEAD : L2_NODE_MEMBER;
linkConfig.myType = (msg[WD_ID_CMD] == L2_HEAD_ID) ? L2_NODE_HEAD : L2_NODE_MEMBER;
linkConfig.myId = msg[WD_ID_CMD];
}
else
@@ -322,7 +383,7 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
.event = L2_ROUTINE_UPDATE,
.msg = &newRtneConfig
};
AssertL2Event(instPtr, &l2Event);
AssertL2Event(linkInstPtr, &l2Event);
break;
}
case 1:
@@ -334,7 +395,7 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
.event = L2_ROUTINE_UPDATE,
.msg = &newRtneConfig
};
AssertL2Event(instPtr, &l2Event);
AssertL2Event(linkInstPtr, &l2Event);
break;
}
case 2:
@@ -346,7 +407,7 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
.event = L2_ROUTINE_UPDATE,
.msg = &newRtneConfig
};
AssertL2Event(instPtr, &l2Event);
AssertL2Event(linkInstPtr, &l2Event);
break;
}
default:
@@ -394,7 +455,7 @@ static int32_t SystemBus_Echo(SYSBUS *instPtr, SYSBUS_UART_FRAME *frame)
/**
* @brief Generate System Bus receive call command response
*/
int32_t SystemBus_GenRecvRsp(SYSBUS *instPtr, SYSMON_SVC_PAYLOAD *payload)
int32_t SystemBus_GenRecvRsp(SYSBUS *instPtr, SYSBUS_SVC_PLD *payload)
{
ASSERT(instPtr != NULL);
ASSERT(payload != NULL);
@@ -410,7 +471,7 @@ int32_t SystemBus_GenRecvRsp(SYSBUS *instPtr, SYSMON_SVC_PAYLOAD *payload)
sysbusRsp->data[WD_CMD] = CMD_RECV_DATA;
sysbusRsp->data[WD_PRD] = MY_PRD_ID;
memcpy(sysbusRsp->data + RECV_DATA_ID_OFFSET, payload, sizeof(SYSMON_SVC_PAYLOAD));
memcpy(sysbusRsp->data + RECV_DATA_ID_OFFSET, payload, sizeof(SYSBUS_SVC_PLD));
if (CircQueuePush(instPtr->txQueue, (void *)sysbusRsp) == false)
{
@@ -527,7 +588,7 @@ int32_t SystemBus_HandleCmd(SYSBUS *instPtr)
}
case CMD_SEND_DATA:
{
Status = SysMonitor_UpdateSendPayload((SYSMON_SVC_PAYLOAD *)(msg + SEND_DATA_ID_OFFSET));
Status = SysMonitor_UpdateSendPayload((SYSBUS_SVC_PLD *)(msg + SEND_DATA_ID_OFFSET));
if (Status == SUCCESS)
{
instPtr->sysbusLog.sendCnt++;
@@ -703,4 +764,302 @@ int32_t SystemBus_RxIntrHandler(SYSBUS *instPtr)
return SUCCESS;
}
/**
* @brief Initialize System monitor
*
* @return SUCCESS
*/
int32_t SysMonitor_Init(SYSMON_CONFIG *config)
{
ASSERT(config != NULL);
sysMonitorInst = calloc(1, sizeof(SYSMONITOR));
if (sysMonitorInst == NULL)
{
return ENOMEM;
}
memcpy(&(sysMonitorInst->config), config, sizeof(SYSMON_CONFIG));
sysMonitorInst->sendQueue = NULL;
sysMonitorInst->recvQueue = NULL;
memset(&(sysMonitorInst->sysInfoCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->linkLogCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->phyLogCtrl), BUFF_NONE, sizeof(PINGPONG));
memset(&(sysMonitorInst->hwStateCtrl), BUFF_NONE, sizeof(PINGPONG));
if (CircQueueCreate(&(sysMonitorInst->sendQueue),
sysMonitorInst->config.sendQueueMax) == false)
{
SysMonitor_Destroy();
return ENOMEM;
}
if (CircQueueCreate(&(sysMonitorInst->recvQueue),
sysMonitorInst->config.recvQueueMax) == false)
{
SysMonitor_Destroy();
return ENOMEM;
}
return SUCCESS;
}
/**
* @brief Destroy system monitor release all allocated memory
*/
void SysMonitor_Destroy(void)
{
free(sysMonitorInst);
}
/**
* @name SystemInfo_API
* @{
*/
/**
* @brief Update system info.
*
* @param info
*/
void SysMonitor_UpdateSysinfo(const SYSINFO *info)
{
ASSERT(info != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->sysInfoCtrl);
sysMonitorInst->sysInfoCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->sysInfo[buffIndx]), info, sizeof(SYSINFO));
sysMonitorInst->sysInfoCtrl.latest = buffIndx;
sysMonitorInst->sysInfoCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get system info.
*
* @param info
*/
void SysMonitor_GetSysinfo(SYSINFO *info)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(info != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->sysInfoCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->sysInfoCtrl);
sysMonitorInst->sysInfoCtrl.rBusy = buffIndx;
memcpy(info, &(sysMonitorInst->sysInfo[buffIndx]), sizeof(SYSINFO));
sysMonitorInst->sysInfoCtrl.rBusy = buffIndex_old;
}
/** @} SystemInfo_API*/
/**
* @name ServicePayload_API
* @{
*/
/**
* @brief Update send payload by
*
* @param payload
*/
int32_t SysMonitor_UpdateSendPayload(SYSBUS_SVC_PLD *payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(payload != NULL);
// validity check
if (payload->dataLen > SYSBUS_PLD_MAX)
{
DBG_ERROR("Payload length %d exceeds valid range.", payload->dataLen);
return EPARAM;
}
// push message into send queue
SYSBUS_SVC_PLD *payloadCopy = malloc(sizeof(SYSBUS_SVC_PLD));
if (payloadCopy == NULL)
{
DBG_ERROR("Allocate memory for send payload failed.\n");
return ENOMEM;
}
memcpy(payloadCopy, payload, sizeof(SYSBUS_SVC_PLD));
if (CircQueuePush(sysMonitorInst->sendQueue, (void *)payloadCopy) == false)
{
DBG_WARNING("SystemMonitor::SEND Queue overflowed!\n");
free(payloadCopy);
return EQUEUE;
}
return SUCCESS;
}
/**
* @brief Get the latest send payload.
*
* @param payload
*/
void SysMonitor_GetSendPayload(SYSBUS_SVC_PLD **payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(payload != NULL);
if (CircQueuePop(sysMonitorInst->sendQueue, (void **)payload) == false)
{
*payload = NULL;
DBG_INFO("SystemMonitor::Empty sendQueue, nothing need sent.\n");
}
}
/**
* @brief Update receive payload.
*
* @param payload
*/
int32_t SysMonitor_GenRecvRsp(SYSBUS_SVC_PLD *payload)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(sysbusDescPtr != NULL);
int32_t Status;
if (payload->dataId == DATA_ID_NONE || payload->dataLen > SYSBUS_PLD_MAX)
{
DBG_INFO("SystemMonitor::Drop invalid message.\n");
return EIGNORE;
}
Status = SystemBus_GenRecvRsp(sysbusDescPtr, payload);
return Status;
}
/** @} ServicePayload_API*/
/**
* @name Linklayer_Log_API
* @{
*/
/**
* @brief Update link layer log
*
* @param log
*/
void SysMonitor_UpdateLinklayerLog(const LINKLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->linkLogCtrl);
sysMonitorInst->linkLogCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->linkLog[buffIndx]), log, sizeof(LINKLOG));
sysMonitorInst->linkLogCtrl.latest = buffIndx;
sysMonitorInst->linkLogCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest link layer log
*
* @param log
*/
void SysMonitor_GetLinklayerLog(LINKLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->linkLogCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->linkLogCtrl);
sysMonitorInst->linkLogCtrl.rBusy = buffIndx;
memcpy(log, &(sysMonitorInst->linkLog[buffIndx]), sizeof(LINKLOG));
sysMonitorInst->linkLogCtrl.rBusy = buffIndex_old;
}
/** @} Linklayer_Log_API*/
/**
* @name PhysicalLayer_Log_API
* @{
*/
/**
* @brief Update physical layer log
*
* @param log
*/
void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->phyLogCtrl);
sysMonitorInst->phyLogCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->phyLog[buffIndx]), log, sizeof(PHYLOG));
sysMonitorInst->phyLogCtrl.latest = buffIndx;
sysMonitorInst->phyLogCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest physical layer log
*
* @param log
*/
void SysMonitor_GetPhysicalLayerLog(PHYLOG *log)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(log != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->phyLogCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->phyLogCtrl);
sysMonitorInst->phyLogCtrl.rBusy = buffIndx;
memcpy(log, &(sysMonitorInst->phyLog[buffIndx]), sizeof(PHYLOG));
sysMonitorInst->phyLogCtrl.rBusy = buffIndex_old;
}
/** @} */
/**
* @name HardwareState_Log_API
* @{
*/
/**
* @brief Log hardware running status.
*
* @param state
*/
void SysMonitor_UpdateHardwareStatus(const HWSTATE *state)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(state != NULL);
uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->hwStateCtrl);
sysMonitorInst->hwStateCtrl.wBusy = buffIndx;
memcpy(&(sysMonitorInst->hwState[buffIndx]), state, sizeof(HWSTATE));
sysMonitorInst->hwStateCtrl.latest = buffIndx;
sysMonitorInst->hwStateCtrl.wBusy = BUFF_NONE;
}
/**
* @brief Get the latest hardware running status.
*
* @param state
*/
void SysMonitor_GetHardwareStatus(HWSTATE *state)
{
ASSERT(sysMonitorInst != NULL);
ASSERT(state != NULL);
uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->hwStateCtrl.rBusy;
if (buffIndex_old != BUFF_NONE)
buffIndx = buffIndex_old; // Keep it busy
else
buffIndx = GetReadable(sysMonitorInst->hwStateCtrl);
sysMonitorInst->hwStateCtrl.rBusy = buffIndx;
memcpy(state, &(sysMonitorInst->hwState[buffIndx]), sizeof(HWSTATE));
sysMonitorInst->hwStateCtrl.rBusy = buffIndex_old;
}
/** @} SystemBus*/
+245 -2
View File
@@ -23,9 +23,74 @@
#include <stdbool.h>
#include "systembus_uart.h" // SystemBus UART driver
#include "circ_queue.h"
#include "../system_monitor.h"
/************************** Constant Definitions *****************************/
/**
* @name SystemMonitor_Constants
* @{
*/
#define SYSBUS_FRM_MAX UART_FRM_MAX
#define SYSBUS_DAT_MAX UART_DAT_MAX
#define SYSBUS_PRE_LEN 2 // length of preamble of data chunk (command + node type)
#define SYSBUS_PLD_MAX SYSBUS_DAT_MAX-SYSBUS_PRE_LEN // max length of payload chunk (part of data chunk)
#define SYSBUS_SVC_PRE_LEN 7 // length of service premable
#define SYSBUS_SVC_PLD_MAX SYSBUS_PLD_MAX-SYSBUS_SVC_PRE_LEN // max length of service payload
#define DATA_ID_NONE UINT32_MAX
#define DATA_ID_TEST 0x02030203
#define VOLTAGE_LSB 0.01 // volt
#define VOLTAGE_MAX 2.55 // volt
#define VOLT_PS_STD 1.0
#define VOLT_PSAUX_STD 1.8
#define VOLT_DDR_STD 1.5
#define VOLT_PL_STD 1.0
#define VOLT_PLAUX_STD 1.8
#define VOLT_BRAM_STD 1.0
#define VOLT_PS_OK BIT(0)
#define VOLT_PSAUX_OK BIT(1)
#define VOLT_DDR_OK BIT(2)
#define VOLT_PL_OK BIT(3)
#define VOLT_PLAUX_OK BIT(4)
#define VOLT_BRAM_OK BIT(5)
#define VOLT_ANT_PROC_OK BIT(0)
#define VOLT_ANT_RF_OK BIT(2)
#define VOLT_ANT_NIL_OK BIT(4)
#define ANT_STATE_OK BIT(6)
// Xilinx Recommended
// #define IS_PS_VALID(x) (x <= 1.05 && x >= 0.95)
// #define IS_PSAUX_VALID(x) (x <= 1.89 && x >= 1.71)
// #define IS_DDR_VALID(x) (x <= 1.89 && x >= 1.14)
// #define IS_PL_VALID(x) (x <= 1.03 && x >= 0.97)
// #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71)
// #define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97)
#define IS_PS_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define IS_PSAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_DDR_VALID(x) ((x) <= 1.7 && (x) >= 1.3)
#define IS_PL_VALID(x) (x <= 1.1 && (x) >= 0.9)
#define IS_PLAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_BRAM_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define CLK_SP_PLL1_LOCK BIT(0)
#define CLK_SP_PLL2_LOCK BIT(2)
#define CLK_AD0_BBPLL_LOCK BIT(0)
#define CLK_AD0_RFPLL_LOCK BIT(2)
#define CLK_AD1_BBPLL_LOCK BIT(4)
#define CLK_AD1_RFPLL_LOCK BIT(6)
#define CLK_ANT_BBPLL_LOCK BIT(0)
#define CLK_ANT_RFPLL1_LOCK BIT(2)
#define CLK_ANT_RFPLL2_LOCK BIT(4)
#define TEMPERATURE_LSB 1.0 // Celsius degree
#define TEMPERATURE_MAX 127.0 // Celsius degree
#define TEMPERATURE_MIN -128.0 // Celsius degree
/** @} SystemMonitor_Constants */
/************************** Data Type Definitions ****************************/
/**
@@ -39,6 +104,156 @@ typedef struct
uint32_t rxQueueMax; ///< maximum rx queue length
} SYSBUS_CONFIG;
/**
* @struct SYSBUS_SVC_PLD
* @brief Payload struct that holds the service payload
*/
typedef struct
{
uint32_t dataId; ///< data identifier
uint8_t nodeId; ///< destination ID for tx, source ID for rx
uint16_t dataLen; ///< data length
uint8_t data[SYSBUS_SVC_PLD_MAX];
} SYSBUS_SVC_PLD;
/**
* @struct SYSINFO
* @brief System Infomation log
*/
typedef struct __attribute__((packed))
{
uint32_t psBDS; ///< -- unit: ms, 0~604799999
uint16_t pBDS; ///< -- unit: week, 0~0~8191
uint32_t psGPS; ///< -- unit: ms, 0~604799999
uint16_t pGPS; ///< -- unit: week, 0~0~8191
uint8_t tmInd; ///< Time validation indicator \n
// -- [0] GPS\n
// -- [1] reserve.\n
// -- [2] UTC\n
// -- [3] BDS\n
float tmFly; ///< Time of flying uint: s
uint8_t stFly; ///< Status of flying \n
// [7:6] departure status 11 - departed/00 - not departed \n
// [5:4] ready status 11 - ready/00 - not ready \n
// [3:2] attitude status 11 - attitude ok/00 - attitude not ok \n
// [1:0] attitude adjust status 11 - adjusted/00 - not adjusted
float posX; ///< coord X Position in launch coordinate system
float posY; ///< coord Y Position in launch coordinate system
float posZ; ///< coord Z Position in launch coordinate system
float vX; ///< Speed X in launch coordinate system
float vY; ///< Speed Y in launch coordinate system
float vZ; ///< Speed Z in launch coordinate system
float pitch; ///< Pitch Attitude in launch inertia coordinate system
float yaw; ///< Yaw Attitude in launch inertia coordinate system
float roll; ///< Roll Attitude in launch inertia coordinate system
} SYSINFO;
/**
* @struct SYSBUSLOG
* @brief System Info holds the system bus log
*/
typedef struct __attribute__((packed))
{
// SystemBus log
uint8_t lastConfig[4]; ///< Last valid config \n
// byte 0: Enable control, 0xAA - enable, 0x55 - disable \n
// byte 1: Node ID \n
// byte 2: Service rate \n
// byte 3: routing table number
uint32_t recvCnt; ///< number of received data packet
uint32_t sendCnt; ///< number of send data packet
uint32_t remoteCnt; ///< number of remote check commands
} SYSBUSLOG;
/**
* @struct LINKLOG
* @brief Linklayer Log struct holds the Linklayer log
*/
typedef struct __attribute__((packed))
{
// Network log
uint32_t tuNum; ///< current time unite number
uint8_t slotNum; ///< current slot number
uint8_t nodeType; ///< current node type
uint8_t cxnStatus; ///< current connection status
uint8_t linkStage; ///< current linklayer working stage
uint32_t recxnCnt; ///< reconnect trial count
uint8_t antIndex; ///< current working antenna index
uint32_t advTxCnt; ///< adv frame send count
uint32_t advRecvCnt; ///< adv frame received count
uint32_t advCorrectCnt; ///< adv frame received correctly count
uint32_t ackTxCnt; ///< ack frame send count
uint32_t ackRecvCnt; ///< ack frame received count
uint32_t ackCorrectCnt; ///< ack frame received correctly count
uint32_t disTxCnt; ///< dist frame send count
uint32_t disRecvCnt; ///< dist frame received count
uint32_t disCorrectCnt;///< dist frame received correctly count
uint32_t mngTxCnt; ///< mng frame send count
uint32_t mngRecvCnt; ///< mng frame received count
uint32_t mngCorrectCnt; ///< mng frame received correctly count
uint32_t rttTxCnt; ///< rtt frame send count
uint32_t rttRecvCnt; ///< rtt frame received count
uint32_t rttCorrectCnt; ///< rtt frame received correctly count
uint32_t svcTxCnt; ///< svc frame send count
uint32_t svcRecvCnt; ///< svc frame received count
uint32_t svcCorrectCnt; ///< svc frame received correctly count
int32_t timeDev; ///< last time deviation result
uint32_t sendId; ///< last send data id
uint32_t recvId; ///< last received data id
uint8_t reserve[3]; ///< reserved data
} LINKLOG;
/**
* @struct PHYLOG
* @brief Physical Layer Log struct holds the Linklayer log
*/
typedef struct __attribute__((packed))
{
uint32_t acqCnt; ///< acquisition count
uint32_t fsyncCnt; ///< frame sync count
uint32_t decodeCnt; ///< decode count
uint32_t crcCnt; ///< crc valid count
double doppler; ///< last doppler estimation result
uint64_t recvStamp; ///< last frame arrival time
double acqPAPR; ///< last acquisition peak-average ration
uint8_t acqPhase; ///< last acquisition phase estimation
uint8_t acqFreqCh; ///< last acquisition frequency deviation estimation
double fsyncPAPR; ///< last frame sync peak-average ration
uint8_t fsyncFreqCh; ///< last frame sync frequency estimation
uint16_t deintlvAmpEst; ///< de-interleave amplitude estimation
uint8_t antControl; ///< current antenna rf mode
uint8_t reserve[2]; ///< reserved data
} PHYLOG;
/**
* @struct HWSTATE
* @brief Hardware Status Log struct holds all hardware status
*/
typedef struct __attribute__((packed))
{
bool isSpOk; ///< signal processor state
bool isAntOk; ///< antenna state
// -- Signal processor status
uint8_t spFpgaVolt; ///< Signal processor voltage state indicator
uint8_t spClkState; ///< Signal processor clock state indicator
uint8_t spAdLockState; ///< Signal processor adc lock state indicator
int8_t spAdTemp_0; ///< Signal processor adc0 temperature
int8_t spAdTemp_1; ///< Signal processor adc1 temperature
int8_t spFpgaTemp; ///< Signal processor FPGA temperature
// -- Antenna status
uint16_t ant1Freq; ///< Antenna 1 frequency
uint16_t ant2Freq; ///< Antenna 2 frequency
uint16_t ant3Freq; ///< Antenna 3 frequency
uint8_t antPll; ///< Antenna pll lock state indicator
uint8_t antMode; ///< Antenna mode indicator
int8_t antTemp; ///< Antenna rf temperature
uint8_t antRsvd; ///< Antenna reserved status register
uint8_t phyId;
uint8_t reserve[3];
} HWSTATE;
/**
* @struct SYSBUS
* @brief SystemBus Instance struct
@@ -57,9 +272,19 @@ typedef struct
bool isRxDone; ///< rx done indicator
} SYSBUS;
/**
* @struct SYSMON_CONFIG
* @brief System monitor config struct holds system monitor initialization parameters
*/
typedef struct
{
uint32_t sendQueueMax; ///< maximum send queue length
uint32_t recvQueueMax; ///< maximum receive queue length
} SYSMON_CONFIG;
/************************** Function Prototypes ******************************/
int32_t SystemBus_GenRecvRsp(SYSBUS *instPtr, SYSMON_SVC_PAYLOAD *payload);
int32_t SystemBus_GenRecvRsp(SYSBUS *instPtr, SYSBUS_SVC_PLD *payload);
int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config);
void SystemBus_Destroy(SYSBUS *instPtr);
@@ -80,6 +305,24 @@ bool SystemBus_IsRespPending(SYSBUS *instPtr);
bool SystemBus_IsTxBusy(SYSBUS *instPtr);
bool SystemBus_IsRxBusy(SYSBUS *instPtr);
int32_t SysMonitor_Init(SYSMON_CONFIG *config);
void SysMonitor_Destroy(void);
void SysMonitor_UpdateSysinfo(const SYSINFO *info);
void SysMonitor_GetSysinfo(SYSINFO *info);
int32_t SysMonitor_UpdateSendPayload(SYSBUS_SVC_PLD *payload);
void SysMonitor_GetSendPayload(SYSBUS_SVC_PLD **payload);
int32_t SysMonitor_GenRecvRsp(SYSBUS_SVC_PLD *payload);
void SysMonitor_UpdateLinklayerLog(const LINKLOG *log);
void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log);
void SysMonitor_UpdateHardwareStatus(const HWSTATE *state);
void SysMonitor_GetLinklayerLog(LINKLOG *log);
void SysMonitor_GetPhysicalLayerLog(PHYLOG *log);
void SysMonitor_GetHardwareStatus(HWSTATE *state);
#endif //__SYSTEMBUS_H_
/** @} SystemBus*/
+12 -58
View File
@@ -21,7 +21,6 @@
* @{
*/
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
@@ -34,10 +33,10 @@
* @{
*/
// Control and status register
#define MODULE_VERSION 0
#define UART_STATUS 4
#define UART_SEND_CMD 8
#define UART_RECV_CNT 12
#define MODULE_VERSION 0x00000000U
#define UART_STATUS 0x0000004U
#define UART_SEND_CMD 0x00000008U
#define UART_RECV_CNT 0x0000000CU
// Status code
#define UART_STATUS_TX_BUSY 0x00010000
@@ -48,6 +47,10 @@
#define UART_RXBUFF_OFFSET 2048
#define UART_RXBUFF_MAX 1024
#if (UART_TXBUFF_MAX < UART_FRM_MAX || UART_RXBUFF_MAX < UART_FRM_MAX)
#error "UART_FRM_MAX exceeds the maximum value."
#endif
// Frame Data offsets
#define FRAME_HEAD_LOW 0x5A
#define FRAME_HEAD_HIGH 0x54
@@ -62,16 +65,6 @@
#define FRAME_OVERHEAD_LEN 7 // CheckSum, Dummy and DataLen
/** @} SystemBus_UART_Driver_Constants*/
/*****************************************************************************/
/**
* @brief Instance initial
*
* @param instPtr A pointer to frame uart instance structure.
* @param config Base address of frame uart, refer to "xparameters.h"
*
* @return None.
*
******************************************************************************/
int SysbusUart_Init(SYSBUS_UART **instPtr, SYSBUS_UART_CONFIG *config)
{
ASSERT(instPtr != NULL);
@@ -85,17 +78,6 @@ int SysbusUart_Init(SYSBUS_UART **instPtr, SYSBUS_UART_CONFIG *config)
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Send a system bus frame.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
* @param buff A pointer to send data buffer
* @param dLen A integer indicate the send data buffer length in byte.
*
* @return
*
******************************************************************************/
int SysbusUart_Send(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame)
{
ASSERT(instPtr != NULL);
@@ -146,23 +128,14 @@ int SysbusUart_Send(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame)
free(sendBuff);
return FAILURE;
}
memcpy((void *)(instPtr->config.baseAddr + UART_TXBUFF_OFFSET), sendBuff, (sendLen + sizeof(uint32_t) - 1) / sizeof(uint32_t) * sizeof(uint32_t));
memcpy((void *)(instPtr->config.baseAddr + UART_TXBUFF_OFFSET), sendBuff,
NORMALIZE_SIZE((sendLen + sizeof(uint32_t) - 1) / sizeof(uint32_t) * sizeof(uint32_t)));
free(sendBuff);
// Start Sending
SYSTEMBUS_UART_mWriteReg(instPtr->config.baseAddr, UART_SEND_CMD, sendLen);
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Get last system bus frame.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
* @param buff A pointer to receive data buffer.
*
* @return
*
******************************************************************************/
int SysbusUart_Recv(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame)
{
ASSERT(instPtr != NULL);
@@ -183,7 +156,8 @@ int SysbusUart_Recv(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame)
{
return ENOMEM;
}
memcpy(dBuff, (void *)(instPtr->config.baseAddr + UART_RXBUFF_OFFSET), sizeof(uint32_t) * dWLen);
memcpy(dBuff, (void *)(instPtr->config.baseAddr + UART_RXBUFF_OFFSET),
NORMALIZE_SIZE(sizeof(uint32_t) * dWLen));
plBuff = dBuff + FRAME_HEAD_LEN;
checkSumCal = 0;
checkSum = plBuff[dLen + FRAME_DUMMY_LEN];
@@ -210,16 +184,6 @@ int SysbusUart_Recv(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame)
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Get rx channel status.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
*
* @return true - SYSBUS_UART rx channel is busy.
* false - SYSBUS_UART rx channel is idle.
*
******************************************************************************/
bool SysbusUart_IsRxBusy(SYSBUS_UART *instPtr)
{
ASSERT(instPtr != NULL);
@@ -236,16 +200,6 @@ bool SysbusUart_IsRxBusy(SYSBUS_UART *instPtr)
}
}
/*****************************************************************************/
/**
* @brief Get tx channel status.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
*
* @return true - SYSBUS_UART tx channel is busy.
* false - SYSBUS_UART tx channel is idle.
*
******************************************************************************/
bool SysbusUart_IsTxBusy(SYSBUS_UART *instPtr)
{
ASSERT(instPtr != NULL);
+57 -6
View File
@@ -27,6 +27,9 @@
#include <stdint.h>
#include <stdbool.h>
#include "util.h"
/************************** Constant Definitions *****************************/
#define UART_FRM_MAX 1024 // max length of uart frame
#define UART_DAT_MAX 1000 // max length of data chunk (part of uart frame)
/**************************** Type Definitions *****************************/
/**
*
@@ -96,23 +99,71 @@ typedef struct
uint16_t len;
uint8_t checkSum;
uint8_t isValid;
uint8_t data[1024];
uint8_t data[UART_FRM_MAX];
} SYSBUS_UART_FRAME;
/************************** Function Prototypes ******************************/
// Instance initial
/*****************************************************************************/
/**
* @brief Instance initial
*
* @param instPtr A pointer to frame uart instance structure.
* @param config Base address of frame uart, refer to "xparameters.h"
*
* @return None.
*
******************************************************************************/
int SysbusUart_Init(SYSBUS_UART **instPtr, SYSBUS_UART_CONFIG *config);
// Send a system bus frame.
/*****************************************************************************/
/**
* @brief Send a system bus frame.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
* @param buff A pointer to send data buffer
* @param dLen A integer indicate the send data buffer length in byte.
*
* @return
*
******************************************************************************/
int SysbusUart_Send(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame);
// Get last system bus frame.
/*****************************************************************************/
/**
* @brief Get last system bus frame.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
* @param buff A pointer to receive data buffer.
*
* @return
*
******************************************************************************/
int SysbusUart_Recv(SYSBUS_UART *instPtr, SYSBUS_UART_FRAME *frame);
// Get system bus rx channel status.
/*****************************************************************************/
/**
* @brief Get rx channel status.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
*
* @return true - SYSBUS_UART rx channel is busy.
* false - SYSBUS_UART rx channel is idle.
*
******************************************************************************/
bool SysbusUart_IsRxBusy(SYSBUS_UART *instPtr);
// Get system bus tx channel status.
/*****************************************************************************/
/**
* @brief Get tx channel status.
*
* @param instPtr A pointer to SYSBUS_UART instance structure.
*
* @return true - SYSBUS_UART tx channel is busy.
* false - SYSBUS_UART tx channel is idle.
*
******************************************************************************/
bool SysbusUart_IsTxBusy(SYSBUS_UART *instPtr);
#endif // SYSTEMBUS_UART_H