2020-11-24 14:45:44 +00:00
|
|
|
// NOTE: the use of ComState "verbs" as commands is not meant as a 1:1 mapping of commands
|
|
|
|
|
// It's just a convenient abuse of already-defined constants. However, it's intended that
|
|
|
|
|
// the COM server on the SoC side abstracts much of the EC bus complexity away.
|
2021-04-01 21:43:47 +00:00
|
|
|
pub(crate) const SERVER_NAME_COM: &str = "_COM manager_";
|
|
|
|
|
|
2021-03-15 18:02:53 +00:00
|
|
|
#[derive(Debug, Default, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2020-11-24 21:11:32 +00:00
|
|
|
pub struct BattStats {
|
|
|
|
|
/// instantaneous voltage in mV
|
|
|
|
|
pub voltage: u16,
|
|
|
|
|
/// state of charge in %, as inferred by impedance tracking
|
|
|
|
|
pub soc: u8,
|
|
|
|
|
/// instantaneous current draw in mA
|
|
|
|
|
pub current: i16,
|
|
|
|
|
/// remaining capacity in mA, as measured by coulomb counting
|
|
|
|
|
pub remaining_capacity: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<[usize; 2]> for BattStats {
|
|
|
|
|
fn from(a: [usize; 2]) -> BattStats {
|
|
|
|
|
BattStats {
|
|
|
|
|
voltage: (a[0] & 0xFFFF) as u16,
|
|
|
|
|
soc: ((a[0] >> 16) & 0xFF) as u8,
|
|
|
|
|
current: ((a[1] >> 16) & 0xFFFF) as i16,
|
|
|
|
|
remaining_capacity: (a[1] & 0xFFFF) as u16,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Into<[usize; 2]> for BattStats {
|
|
|
|
|
fn into(self) -> [usize; 2] {
|
2021-01-03 10:31:51 +00:00
|
|
|
[
|
|
|
|
|
(self.voltage as usize & 0xffff) | ((self.soc as usize) << 16) & 0xFF_0000,
|
|
|
|
|
(self.remaining_capacity as usize & 0xffff)
|
|
|
|
|
| ((self.current as usize) << 16) & 0xffff_0000,
|
|
|
|
|
]
|
2020-11-24 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-05-23 20:34:50 +00:00
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
|
|
|
|
pub enum FlashOp {
|
|
|
|
|
/// erase a region defined by (address, len)
|
|
|
|
|
Erase(u32, u32),
|
|
|
|
|
/// Send up to 1kiB of data at a time. This reduces messaging overhead and makes
|
|
|
|
|
/// programming more efficient, while taking full advantage of the 1280-deep receive FIFO on the EC.
|
|
|
|
|
/// Address + up to 4 pages. page 0 is at address, page 1 is at address + 256, etc.
|
|
|
|
|
/// Pages stored as None are skipped, yet the address pointer is still incremented.
|
|
|
|
|
Program(u32, [Option<[u8; 256]>; 4])
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
|
|
|
|
pub enum FlashResult {
|
|
|
|
|
Pass,
|
|
|
|
|
Fail,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
|
|
|
|
pub struct FlashRecord {
|
|
|
|
|
/// identifier to validate that we're authorized to do this
|
|
|
|
|
pub id: [u32; 4],
|
|
|
|
|
/// operation
|
|
|
|
|
pub op: FlashOp,
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 21:43:47 +00:00
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
|
|
|
|
pub(crate) enum Opcode {
|
2020-11-24 14:45:44 +00:00
|
|
|
/// Battery stats
|
|
|
|
|
BattStats,
|
|
|
|
|
|
2021-04-16 11:58:05 +00:00
|
|
|
/// Standby current -- only valid if a BattStats command was previously issued
|
|
|
|
|
StandbyCurrent,
|
|
|
|
|
|
2020-11-25 11:58:24 +00:00
|
|
|
/// Battery stats, non-blocking
|
|
|
|
|
BattStatsNb,
|
|
|
|
|
|
2020-11-24 21:11:32 +00:00
|
|
|
/// Query Full charge capacity of the battery
|
2021-04-01 21:43:47 +00:00
|
|
|
//BattFullCapacity,
|
2020-11-24 21:11:32 +00:00
|
|
|
|
2020-11-24 14:45:44 +00:00
|
|
|
/// Turn Boost Mode On
|
debugging BOOST mode glitch issue
Here's an arcane bug for you:
When powering down, the Spartan 7 3.3V I/O drivers will
output a roughly 800us wide glitch as 3.3V falls below around
1.7V, if the 0.95V core voltage comes down first (which it does
because we have an active discharge on 0.95V, but not on 3.3V).
In this case, it's just wide and high enough to cause the
BOOST mode line to engage, which takes the BOOST output
and ties it to VBUS, which is just enough for the system to
think you're powering it back on again. Which is not what
you want when powering down.
The ultimate fix was to put a heftier pull-down on the BOOST
line so that it can't trip the BOOST output into the VBUS.
Another option could be more active discharge FETs, but that
would require a full board spin and we are already at certification,
so we'll stick with the stronger pull-down on BOOST. It seems to
be a robust fix in the worst corner cases we can find.
The downside is that when powering an external USB device,
you are burning an extra 30mW of power overcoming the pull-down,
but typically, any external USB devices plugged into Precursor
will burn far in excess of that, so the delta should be negligible.
2021-04-23 07:33:14 +00:00
|
|
|
BoostOn,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Turn Boost Mode Off
|
debugging BOOST mode glitch issue
Here's an arcane bug for you:
When powering down, the Spartan 7 3.3V I/O drivers will
output a roughly 800us wide glitch as 3.3V falls below around
1.7V, if the 0.95V core voltage comes down first (which it does
because we have an active discharge on 0.95V, but not on 3.3V).
In this case, it's just wide and high enough to cause the
BOOST mode line to engage, which takes the BOOST output
and ties it to VBUS, which is just enough for the system to
think you're powering it back on again. Which is not what
you want when powering down.
The ultimate fix was to put a heftier pull-down on the BOOST
line so that it can't trip the BOOST output into the VBUS.
Another option could be more active discharge FETs, but that
would require a full board spin and we are already at certification,
so we'll stick with the stronger pull-down on BOOST. It seems to
be a robust fix in the worst corner cases we can find.
The downside is that when powering an external USB device,
you are burning an extra 30mW of power overcoming the pull-down,
but typically, any external USB devices plugged into Precursor
will burn far in excess of that, so the delta should be negligible.
2021-04-23 07:33:14 +00:00
|
|
|
BoostOff,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
2021-05-16 08:52:27 +00:00
|
|
|
/// Read the current accelerations off the IMU; this blocks while the read takes place
|
|
|
|
|
ImuAccelReadBlocking,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Power off the SoC
|
|
|
|
|
PowerOffSoc,
|
|
|
|
|
|
|
|
|
|
/// Ship mode (battery disconnect)
|
2021-04-22 10:07:27 +00:00
|
|
|
ShipMode,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Is the battery charging?
|
2021-05-16 08:30:58 +00:00
|
|
|
IsCharging,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Set the backlight brightness
|
2021-05-15 20:29:12 +00:00
|
|
|
SetBackLight,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Request charging
|
2021-05-16 08:30:58 +00:00
|
|
|
RequestCharging,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
2021-05-23 20:34:50 +00:00
|
|
|
/// Erase or program a region of EC FLASH
|
|
|
|
|
FlashOp,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
2021-05-23 20:34:50 +00:00
|
|
|
/// Take the mutex on EC update operations.
|
|
|
|
|
/// Only one process is allowed to acquire this ever, right now, for security reasons.
|
|
|
|
|
FlashAcquire,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
2021-04-16 15:07:31 +00:00
|
|
|
/// Checks if an updated SSID list is available
|
|
|
|
|
SsidCheckUpdate,
|
2020-11-24 14:45:44 +00:00
|
|
|
|
|
|
|
|
/// Return the latest SSID list
|
2021-04-16 15:07:31 +00:00
|
|
|
SsidFetchAsString,
|
2020-12-31 11:31:12 +00:00
|
|
|
|
|
|
|
|
/// Fetch the git ID of the EC
|
|
|
|
|
EcGitRev,
|
|
|
|
|
|
|
|
|
|
/// Fetch the firmware rev of the WF200
|
|
|
|
|
Wf200Rev,
|
|
|
|
|
|
|
|
|
|
/// Send a line of PDS data
|
2021-04-01 21:43:47 +00:00
|
|
|
Wf200PdsLine, //String<512>
|
2021-01-12 10:44:02 +00:00
|
|
|
|
|
|
|
|
/// request for a listener to BattStats events
|
2021-04-01 21:43:47 +00:00
|
|
|
RegisterBattStatsListener, //String<64>
|
2021-04-14 14:43:23 +00:00
|
|
|
|
|
|
|
|
/// Reset the wifi chip
|
|
|
|
|
Wf200Reset,
|
|
|
|
|
|
|
|
|
|
/// Disable the wifi chip
|
|
|
|
|
Wf200Disable,
|
2021-04-14 20:10:47 +00:00
|
|
|
|
|
|
|
|
/// start passive SSID scanning
|
|
|
|
|
ScanOn,
|
|
|
|
|
|
|
|
|
|
/// stop passive SSID scanning
|
|
|
|
|
ScanOff,
|
2021-04-29 15:53:35 +00:00
|
|
|
|
|
|
|
|
/// suspend/resume callback
|
|
|
|
|
SuspendResume,
|
2021-07-06 08:29:58 +00:00
|
|
|
|
|
|
|
|
/// wlan: make sure radio is on (reset from standby if needed)
|
|
|
|
|
WlanOn,
|
|
|
|
|
|
|
|
|
|
/// wlan: switch radio to lowest power standby mode
|
|
|
|
|
WlanOff,
|
|
|
|
|
|
|
|
|
|
/// wlan: set SSID to use for joining AP
|
|
|
|
|
WlanSetSSID,
|
|
|
|
|
|
|
|
|
|
/// wlan: set password to use for joining AP
|
|
|
|
|
WlanSetPass,
|
|
|
|
|
|
|
|
|
|
/// wlan: join AP using previously set SSID & password
|
|
|
|
|
WlanJoin,
|
|
|
|
|
|
|
|
|
|
/// wlan: disconnect from AP
|
|
|
|
|
WlanLeave,
|
|
|
|
|
|
2021-07-07 08:43:20 +00:00
|
|
|
/// wlan: get wlan radio status (power state? connected? AP info?)
|
|
|
|
|
WlanStatus,
|
2020-11-24 14:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-01 21:43:47 +00:00
|
|
|
/// These enums indicate what kind of callback type we're sending.
|
|
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
2021-04-02 08:40:17 +00:00
|
|
|
pub(crate) enum Callback {
|
2021-04-01 21:43:47 +00:00
|
|
|
/// Battery status
|
|
|
|
|
BattStats,
|
2021-04-02 08:40:17 +00:00
|
|
|
/// Server is quitting, drop connections
|
|
|
|
|
Drop,
|
2021-04-01 21:43:47 +00:00
|
|
|
}
|