add usb proto files
This commit is contained in:
parent
358e83c419
commit
47319963e9
2 changed files with 82 additions and 0 deletions
31
include/proto_usb.h
Normal file
31
include/proto_usb.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef __PROTO_USB_H__
|
||||
#define __PROTO_USB_H__
|
||||
|
||||
enum usbp_pkt_type {
|
||||
USBP_GET_STATUS = 0,
|
||||
USBP_GET_MEASUREMENTS = 1,
|
||||
};
|
||||
|
||||
struct __attribute__((__packed__)) usbp_status_pkt {
|
||||
uint8_t packet_type;
|
||||
uint64_t sys_time_us;
|
||||
uint8_t has_lcd;
|
||||
uint8_t has_adc;
|
||||
uint8_t board_config;
|
||||
uint8_t bus_addr;
|
||||
ErrorCode last_uart_error;
|
||||
uint64_t last_uart_error_timestamp;
|
||||
uint64_t last_uart_rx;
|
||||
uint64_t last_uart_tx;
|
||||
ErrorCode last_bus_error;
|
||||
uint64_t last_bus_error_timestamp;
|
||||
};
|
||||
|
||||
struct __attribute__((__packed__)) usbp_measurement_pkt {
|
||||
uint8_t packet_type;
|
||||
uint8_t num_channels;
|
||||
int32_t measurements[2][2][64];
|
||||
};
|
||||
|
||||
|
||||
#endif /* __PROTO_USB_H__ */
|
||||
51
src/proto_usb.c
Normal file
51
src/proto_usb.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
#include <global.h>
|
||||
#include <proto.h>
|
||||
#include <proto_usb.h>
|
||||
#include <usb_if.h>
|
||||
#include <usb_proto.h>
|
||||
|
||||
void handle_usb_packet(void *packet, size_t len) {
|
||||
switch (*(uint8_t *)packet) {
|
||||
case USBP_GET_STATUS: {
|
||||
struct usbp_status_pkt response = {
|
||||
.packet_type = USBP_GET_STATUS,
|
||||
.sys_time_us = sys_time_us,
|
||||
.has_adc = st_adc.has_adc,
|
||||
.has_lcd = st_lcd.has_lcd,
|
||||
.board_config = board_config,
|
||||
.bus_addr = uart_st.addr,
|
||||
.last_uart_error = uart_st.error,
|
||||
.last_uart_error_timestamp = uart_st.last_error,
|
||||
.last_uart_rx = uart_st.last_packet,
|
||||
.last_uart_tx = uart_st.last_transmission,
|
||||
.last_bus_error = st_proto.error,
|
||||
.last_bus_error_timestamp = st_proto.last_error,
|
||||
};
|
||||
usb_write_response(&response, sizeof(response));
|
||||
break;
|
||||
}
|
||||
|
||||
case USBP_GET_MEASUREMENTS: {
|
||||
struct usbp_measurement_pkt response = {
|
||||
.packet_type = USBP_GET_MEASUREMENTS,
|
||||
.num_channels = 4,
|
||||
};
|
||||
|
||||
for (size_t board=0; board=2; board++) {
|
||||
|
||||
size_t src_idx = adc_sp_rd_idx[board];
|
||||
for (size_t i=0; i<COUNT_OF(response.measurements[0][0]); i++) {
|
||||
for (size_t channel=0; channel=2; channel++) {
|
||||
response.measurements[board][channel][i] =
|
||||
}
|
||||
src_idx ++;
|
||||
if (src_idx ==
|
||||
}
|
||||
}
|
||||
|
||||
usb_write_response(&response, sizeof(response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue