Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@
// "--compile-commands-dir=build_fw_test",
"--query-driver=/usr/local/bin/arm-none-eabi-gcc"
],
"files.associations": {}
"files.associations": {
"hw_chimeraconfig_v2.h": "c",
"hw_pwminput.h": "c",
"hw_spis.h": "c",
"hw_pwmoutput.h": "c",
"hw_gpios.h": "c",
"shared.pb.h": "c",
"ssm.pb.h": "c",
"pb.h": "c",
"hw_pwms.h": "c",
"hw_spi.h": "c",
"main.h": "c",
"hw_i2c.h": "c",
"stdint.h": "c",
"hw_pwminputfreqonly.h": "c",
"hw_hal.h": "c",
"format": "c",
"hw_chimera_v2.h": "c",
"hw_usb.h": "c",
"io_log.h": "c",
"usb_device.h": "c"
}
}
1 change: 1 addition & 0 deletions firmware/chimera/proto/nanopb
Submodule nanopb added at a664f8
2 changes: 1 addition & 1 deletion firmware/chimera/proto/shared.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ message I2cNetName {
oneof name {
DAM.I2cNetName dam_net_name = 6;
}
}
}
64 changes: 64 additions & 0 deletions firmware/chimera_v2/chimera_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,71 @@ def spi_device(self, net_name: str) -> SpiDevice:

"""
return SpiDevice(self, net_name)

def pwm_input(self, net_name: str) -> SpiDevice:
"""Read incoming PWM signal's frequency and duty cycle.

Args:
net_name: Identifier of the PWM sender.

Returns:
Frequency and duty cycle values.

"""
request = proto_autogen.shared_pb2.ChimeraV2Request()
setattr(
request.pwm_read.net_name,
self._net_name_tag,
self.board_module.PwmNetName.Value(net_name),
)
self._write(request)

# Wait for response.
response = self._read()
assert response.WhichOneof("payload") == "pwm_full_input"
return {"freq_hz":response.pwm_full_input.frequency_hz, "duty_cycle": response.pwn_full_input.duty_cycle}

def pwm_input_freq_only(self, net_name: str) -> SpiDevice:
"""Read incoming PWM signal's frequency only.

Args:
net_name: Identifier of the PWM sender.

Returns:
Only the frequency value of the PWM signal.

"""
request = proto_autogen.shared_pb2.ChimeraV2Request()
setattr(
request.pwm_read.net_name,
self._net_name_tag,
self.board_module.PwmNetName.Value(net_name),
)
self._write(request)

# Wait for response.
response = self._read()
assert response.WhichOneof("payload") == "pwm_freq_only_input"
return {"freq_hz":response.pwm_full_input.frequency_hz}

def pwm_output(self, net_name: str, duty_cycle: float, frequency_hz: float) -> SpiDevice:
"""Send a PWM signal to a designated board with specific timer channel frequency and desired duty cycle.

Args:
net_name: Identifier of the PWM receiver.
"""
request = proto_autogen.shared_pb2.ChimeraV2Request()
setattr(
request.pwm_read.net_name,
self._net_name_tag,
self.board_module.PwmNetName.Value(net_name),
)
self._write(request)

# Wait for response.
response = self._read()
assert response.WhichOneof("payload") == "pwm_full_output"
return {"freq_hz":response.pwm_full_output.frequency_hz}

class I2cDevice:
def __init__(self, owner: _Board, net_name: str):
Expand Down
5 changes: 5 additions & 0 deletions firmware/chimera_v2/proto/bms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ enum SpiNetName {
SPI_NET_NAME_UNSPECIFIED = 0;
SPI_LTC6813_LS = 1;
SPI_LTC6813_HS = 2;
}

enum PwmNetName {
PWM_NET_NAME_UNSPECIFIED = 0;
PWM_CHARGER = 1;
}
5 changes: 5 additions & 0 deletions firmware/chimera_v2/proto/crit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ enum GpioNetName {
GPIO_LED_SRCK = 15;
GPIO_SEVEN_SEG_SRCK = 16;
}

enum PwmNetName {
PWM_NET_NAME_UNSPECIFIED = 0;
PWM_LED_BRIGHTNESS = 0;
}
5 changes: 5 additions & 0 deletions firmware/chimera_v2/proto/rsm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ enum I2cNetName {
I2C_IMU_I2C = 1;
I2C_R_PUMP_I2C = 2;
}

enum PwmNetName {
PWM_NET_NAME_UNSPECIFIED = 0;
PWM_FLOW_RATE_LPS = 1;
}
50 changes: 50 additions & 0 deletions firmware/chimera_v2/proto/shared.proto
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,46 @@ message SpiTransactionResponse {
bytes rx_data = 1 [(nanopb).max_size = 128];
}

/* PWMs */
message PwmNetName {
oneof name {
bms.PwmNetName bms_net_name = 1;
rsm.PwmNetName rsm_net_name = 2;
crit.PwmNetName crit_net_name = 3;
}
}

message PwmInputRequest {
PwmNetName net_name = 1;
float frequency_hz = 2;
float duty_cycle = 3;
}

message FullPwmInputResponse {
float measured_frequency_hz = 1;
float measured_duty_cycle = 2;
}

message PwmInputFreqOnlyRequest {
PwmNetName net_name = 1;
float frequency_hz = 2;
}

message FreqOnlyPwmInputResponse {
float measured_frequency_hz = 1;
}

message PwmOutputRequest {
PwmNetName net_name = 1;
float frequency_hz = 2;
float duty_cycle = 3;
}

message PwmOutputResponse {
float assigned_frequency_hz = 2;
float assigned_duty_cycle = 3;
}

/*
Wrapper around all messages

Expand Down Expand Up @@ -205,6 +245,11 @@ message ChimeraV2Request {
SpiReceiveRequest spi_receive = 9;
SpiTransmitRequest spi_transmit = 10;
SpiTransactionRequest spi_transaction = 11;

// PWM.
PwmInputRequest pwm_full_input = 12;
PwmInputFreqOnlyRequest pwm_freq_only_input = 13;
PwmOutputRequest pwm_full_output = 14;
}
}

Expand All @@ -228,5 +273,10 @@ message ChimeraV2Response {
SpiReceiveResponse spi_receive = 9;
SpiTransmitResponse spi_transmit = 10;
SpiTransactionResponse spi_transaction = 11;

// PWM.
FullPwmInputResponse pwm_full_input = 12;
FreqOnlyPwmInputResponse pwm_freq_only_input = 13;
PwmOutputResponse pwm_full_output = 14;
}
}
8 changes: 5 additions & 3 deletions firmware/chimera_v2/proto_autogen/bms_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 3, '', 'bms.proto')
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 4, '', 'bms.proto')
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tbms.proto\x12\x03bms*\xaa\x05\n\x0bGpioNetName\x12\x1d\n\x19GPIO_NET_NAME_UNSPECIFIED\x10\x00\x12\r\n\tGPIO_LEDB\x10\x01\x12\x10\n\x0cGPIO_BSPD_OK\x10\x02\x12\x17\n\x13GPIO_ACCEL_BRAKE_OK\x10\x03\x12\x19\n\x15GPIO_nBRAKE_PRESS_3V3\x10\x04\x12\x1b\n\x17GPIO_nHIGH_CURRENT_BSPD\x10\x05\x12\x15\n\x11GPIO_MSD_SHDN_SNS\x10\x06\x12\x18\n\x14GPIO_HV_P_INTLCK_SNS\x10\x07\x12\x18\n\x14GPIO_HV_N_INTLCK_SNS\x10\x08\x12\x12\n\x0eGPIO_IMD_LATCH\x10\t\x12\r\n\tGPIO_DIAG\x10\n\x12\x0e\n\nGPIO_SD_CD\x10\x0b\x12\r\n\tGPIO_LEDR\x10\x0c\x12\x12\n\x0eGPIO_SPI_CS_LS\x10\r\x12\x14\n\x10GPIO_TSENSE_SEL0\x10\x0e\x12\x14\n\x10GPIO_TSENSE_SEL1\x10\x0f\x12\x14\n\x10GPIO_TSENSE_SEL2\x10\x10\x12\x15\n\x11GPIO_BSPD_TEST_EN\x10\x11\x12\x1e\n\x1aGPIO_TS_ISENSE_OCSC_OK_3V3\x10\x12\x12\x12\n\x0eGPIO_SPI_CS_HS\x10\x13\x12\x0f\n\x0bGPIO_BMS_OK\x10\x14\x12\x19\n\x15GPIO_nEVSE_I_LIM_GPIO\x10\x15\x12\x10\n\x0cGPIO_IR_P_EN\x10\x16\x12\x10\n\x0cGPIO_SHDN_EN\x10\x17\x12\x12\n\x0eGPIO_BMS_LATCH\x10\x18\x12\x0f\n\x0bGPIO_IMD_OK\x10\x19\x12\x13\n\x0fGPIO_BSPD_LATCH\x10\x1a\x12\x16\n\x12GPIO_PRE_CHARGE_EN\x10\x1b\x12\x15\n\x11GPIO_FB_STBY_SHDN\x10\x1c\x12\x0f\n\x0bGPIO_FAN_EN\x10\x1d\x12\x12\n\x0eGPIO_FAN_PGOOD\x10\x1e*\xbe\x01\n\nAdcNetName\x12\x1c\n\x18ADC_NET_NAME_UNSPECIFIED\x10\x00\x12\x10\n\x0cADC_FAN_ISNS\x10\x01\x12\x13\n\x0fADC_TS_VSENSE_P\x10\x02\x12\x13\n\x0fADC_TS_VSENSE_N\x10\x03\x12\x11\n\rADC_SHDN_ISNS\x10\x04\x12\x18\n\x14ADC_EMETER_THERM_SNS\x10\x05\x12\x14\n\x10ADC_TS_ISNS_400A\x10\x06\x12\x13\n\x0fADC_TS_ISNS_50A\x10\x07*R\n\nSpiNetName\x12\x1c\n\x18SPI_NET_NAME_UNSPECIFIED\x10\x00\x12\x12\n\x0eSPI_LTC6813_LS\x10\x01\x12\x12\n\x0eSPI_LTC6813_HS\x10\x02b\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tbms.proto\x12\x03bms*\xaa\x05\n\x0bGpioNetName\x12\x1d\n\x19GPIO_NET_NAME_UNSPECIFIED\x10\x00\x12\r\n\tGPIO_LEDB\x10\x01\x12\x10\n\x0cGPIO_BSPD_OK\x10\x02\x12\x17\n\x13GPIO_ACCEL_BRAKE_OK\x10\x03\x12\x19\n\x15GPIO_nBRAKE_PRESS_3V3\x10\x04\x12\x1b\n\x17GPIO_nHIGH_CURRENT_BSPD\x10\x05\x12\x15\n\x11GPIO_MSD_SHDN_SNS\x10\x06\x12\x18\n\x14GPIO_HV_P_INTLCK_SNS\x10\x07\x12\x18\n\x14GPIO_HV_N_INTLCK_SNS\x10\x08\x12\x12\n\x0eGPIO_IMD_LATCH\x10\t\x12\r\n\tGPIO_DIAG\x10\n\x12\x0e\n\nGPIO_SD_CD\x10\x0b\x12\r\n\tGPIO_LEDR\x10\x0c\x12\x12\n\x0eGPIO_SPI_CS_LS\x10\r\x12\x14\n\x10GPIO_TSENSE_SEL0\x10\x0e\x12\x14\n\x10GPIO_TSENSE_SEL1\x10\x0f\x12\x14\n\x10GPIO_TSENSE_SEL2\x10\x10\x12\x15\n\x11GPIO_BSPD_TEST_EN\x10\x11\x12\x1e\n\x1aGPIO_TS_ISENSE_OCSC_OK_3V3\x10\x12\x12\x12\n\x0eGPIO_SPI_CS_HS\x10\x13\x12\x0f\n\x0bGPIO_BMS_OK\x10\x14\x12\x19\n\x15GPIO_nEVSE_I_LIM_GPIO\x10\x15\x12\x10\n\x0cGPIO_IR_P_EN\x10\x16\x12\x10\n\x0cGPIO_SHDN_EN\x10\x17\x12\x12\n\x0eGPIO_BMS_LATCH\x10\x18\x12\x0f\n\x0bGPIO_IMD_OK\x10\x19\x12\x13\n\x0fGPIO_BSPD_LATCH\x10\x1a\x12\x16\n\x12GPIO_PRE_CHARGE_EN\x10\x1b\x12\x15\n\x11GPIO_FB_STBY_SHDN\x10\x1c\x12\x0f\n\x0bGPIO_FAN_EN\x10\x1d\x12\x12\n\x0eGPIO_FAN_PGOOD\x10\x1e*\xbe\x01\n\nAdcNetName\x12\x1c\n\x18ADC_NET_NAME_UNSPECIFIED\x10\x00\x12\x10\n\x0cADC_FAN_ISNS\x10\x01\x12\x13\n\x0fADC_TS_VSENSE_P\x10\x02\x12\x13\n\x0fADC_TS_VSENSE_N\x10\x03\x12\x11\n\rADC_SHDN_ISNS\x10\x04\x12\x18\n\x14ADC_EMETER_THERM_SNS\x10\x05\x12\x14\n\x10ADC_TS_ISNS_400A\x10\x06\x12\x13\n\x0fADC_TS_ISNS_50A\x10\x07*R\n\nSpiNetName\x12\x1c\n\x18SPI_NET_NAME_UNSPECIFIED\x10\x00\x12\x12\n\x0eSPI_LTC6813_LS\x10\x01\x12\x12\n\x0eSPI_LTC6813_HS\x10\x02*;\n\nPwmNetName\x12\x1c\n\x18PWM_NET_NAME_UNSPECIFIED\x10\x00\x12\x0f\n\x0bPWM_CHARGER\x10\x01b\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'bms_pb2', _globals)
Expand All @@ -17,4 +17,6 @@
_globals['_ADCNETNAME']._serialized_start = 704
_globals['_ADCNETNAME']._serialized_end = 894
_globals['_SPINETNAME']._serialized_start = 896
_globals['_SPINETNAME']._serialized_end = 978
_globals['_SPINETNAME']._serialized_end = 978
_globals['_PWMNETNAME']._serialized_start = 980
_globals['_PWMNETNAME']._serialized_end = 1039
17 changes: 16 additions & 1 deletion firmware/chimera_v2/proto_autogen/bms_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,19 @@ class SpiNetName(_SpiNetName, metaclass=_SpiNetNameEnumTypeWrapper):
SPI_NET_NAME_UNSPECIFIED: SpiNetName.ValueType
SPI_LTC6813_LS: SpiNetName.ValueType
SPI_LTC6813_HS: SpiNetName.ValueType
global___SpiNetName = SpiNetName
global___SpiNetName = SpiNetName

class _PwmNetName:
ValueType = typing.NewType('ValueType', builtins.int)
V: typing_extensions.TypeAlias = ValueType

class _PwmNetNameEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_PwmNetName.ValueType], builtins.type):
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
PWM_NET_NAME_UNSPECIFIED: _PwmNetName.ValueType
PWM_CHARGER: _PwmNetName.ValueType

class PwmNetName(_PwmNetName, metaclass=_PwmNetNameEnumTypeWrapper):
...
PWM_NET_NAME_UNSPECIFIED: PwmNetName.ValueType
PWM_CHARGER: PwmNetName.ValueType
global___PwmNetName = PwmNetName
16 changes: 0 additions & 16 deletions firmware/chimera_v2/proto_autogen/crit_pb2.py

This file was deleted.

63 changes: 0 additions & 63 deletions firmware/chimera_v2/proto_autogen/crit_pb2.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion firmware/chimera_v2/proto_autogen/dam_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 3, '', 'dam.proto')
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 4, '', 'dam.proto')
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tdam.proto\x12\x03dam*\x9e\x02\n\x0bGpioNetName\x12\x1d\n\x19GPIO_NET_NAME_UNSPECIFIED\x10\x00\x12\x15\n\x11GPIO_TELEM_PWR_EN\x10\x01\x12\x16\n\x12GPIO_BUZZER_PWR_EN\x10\x02\x12\x14\n\x10GPIO_TSIM_RED_EN\x10\x03\x12\x15\n\x11GPIO_NTSIM_GRN_EN\x10\x04\x12\x15\n\x11GPIO_R_SHDN_SENSE\x10\x05\x12\x15\n\x11GPIO_L_SHDN_SENSE\x10\x06\x12\x0c\n\x08GPIO_LED\x10\x07\x12\r\n\tGPIO_BOOT\x10\x08\x12\x13\n\x0fGPIO_SD_PRESENT\x10\t\x12\x13\n\x0fGPIO_N_RTC_INT1\x10\n\x12\r\n\tGPIO_900M\x10\x0b\x12\x10\n\x0cGPIO_SD_FAIL\x10\x0c*7\n\nI2cNetName\x12\x1c\n\x18I2C_NET_NAME_UNSPECIFIED\x10\x00\x12\x0b\n\x07I2C_RTC\x10\x01b\x06proto3')
_globals = globals()
Expand Down
2 changes: 1 addition & 1 deletion firmware/chimera_v2/proto_autogen/f4dev_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 3, '', 'f4dev.proto')
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 4, '', 'f4dev.proto')
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bf4dev.proto\x12\x05f4dev*D\n\x0bGpioNetName\x12\x1d\n\x19GPIO_NET_NAME_UNSPECIFIED\x10\x00\x12\n\n\x06GPIO_6\x10\x01\x12\n\n\x06GPIO_5\x10\x02b\x06proto3')
_globals = globals()
Expand Down
2 changes: 1 addition & 1 deletion firmware/chimera_v2/proto_autogen/fsm_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 3, '', 'fsm.proto')
_runtime_version.ValidateProtobufRuntimeVersion(_runtime_version.Domain.PUBLIC, 5, 29, 4, '', 'fsm.proto')
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tfsm.proto\x12\x03fsm*\xb1\x02\n\x0bGpioNetName\x12\x1d\n\x19GPIO_NET_NAME_UNSPECIFIED\x10\x00\x12\x11\n\rGPIO_BOTS_3v3\x10\x01\x12\x19\n\x15GPIO_COCKPIT_SHDN_3v3\x10\x02\x12\x11\n\rGPIO_IMU_INT1\x10\x03\x12\x11\n\rGPIO_IMU_INT2\x10\x04\x12\x16\n\x12GPIO_NSUSP_FL_OCSC\x10\x05\x12\x16\n\x12GPIO_NSUSP_FR_OCSC\x10\x06\x12\x13\n\x0fGPIO_FR_INT_3v3\x10\x07\x12\x13\n\x0fGPIO_FL_INT_3v3\x10\x08\x12\x12\n\x0eGPIO_DEBUG_LED\x10\t\x12\x18\n\x14GPIO_NSTR_ANGLE_OCSC\x10\n\x12\x14\n\x10GPIO_NBPS_F_OCSC\x10\x0b\x12\x11\n\rGPIO_BOOT_LED\x10\x0c*\x8c\x01\n\nAdcNetName\x12\x1c\n\x18ADC_NET_NAME_UNSPECIFIED\x10\x00\x12\x0f\n\x0bADC_SUSP_FL\x10\x01\x12\x0f\n\x0bADC_SUSP_FR\x10\x02\x12\r\n\tADC_APPS2\x10\x03\x12\r\n\tADC_BPS_F\x10\x04\x12\x11\n\rADC_STR_ANGLE\x10\x05\x12\r\n\tADC_APPS1\x10\x06*7\n\nI2cNetName\x12\x1c\n\x18I2C_NET_NAME_UNSPECIFIED\x10\x00\x12\x0b\n\x07I2C_IMU\x10\x01b\x06proto3')
_globals = globals()
Expand Down
Loading