mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-11 18:53:47 +08:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 095ef5f9f6 | |||
| fd71fe698c | |||
| d5242c5b82 | |||
| 1f1893a170 | |||
| 5808958fb2 | |||
| e90c41c576 | |||
| aa1b61eb8e | |||
| f448d357e0 | |||
| 98cd6147c3 | |||
| 30bb73d527 | |||
| d22636b194 | |||
| 4808de10d6 | |||
| a440425ef8 | |||
| 61bbb52172 | |||
| cf5c4aeacb | |||
| 94053536b4 | |||
| b539ae3e2d | |||
| cd98235644 | |||
| 1ff59baea7 | |||
| c8b4633cd1 | |||
| 813d5b9982 | |||
| 53413fa019 | |||
| 63da1abe2c | |||
| be28530ee4 | |||
| 13bdfcdd95 | |||
| 9675794969 | |||
| 151a504507 | |||
| 03e764bcb3 | |||
| 16eb74250c | |||
| 4a48ef8dbc | |||
| 76ab558ca6 |
@@ -32,6 +32,9 @@ selfdrive/proclogd/proclogd
|
|||||||
selfdrive/ui/ui
|
selfdrive/ui/ui
|
||||||
selfdrive/test/tests/plant/out
|
selfdrive/test/tests/plant/out
|
||||||
selfdrive/visiond/visiond
|
selfdrive/visiond/visiond
|
||||||
|
selfdrive/loggerd/loggerd
|
||||||
|
selfdrive/sensord/gpsd
|
||||||
|
selfdrive/sensord/sensord
|
||||||
/src/
|
/src/
|
||||||
|
|
||||||
one
|
one
|
||||||
|
|||||||
+1
-17
@@ -3,21 +3,5 @@ sudo: required
|
|||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
install:
|
|
||||||
- docker build -t tmppilot -f Dockerfile.openpilot .
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- docker run
|
- ./run_docker_tests.sh
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/ && ./test_fingerprints.py'
|
|
||||||
- docker run
|
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools")'
|
|
||||||
- docker run
|
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools"); exit $(($? & 3))'
|
|
||||||
- docker run tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover common'
|
|
||||||
- docker run tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/can'
|
|
||||||
- docker run tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/boardd'
|
|
||||||
- docker run tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/controls'
|
|
||||||
- docker run tmppilot /bin/sh -c 'cd /tmp/openpilot/ && python -m unittest discover selfdrive/loggerd'
|
|
||||||
- docker run
|
|
||||||
-v "$(pwd)"/selfdrive/test/tests/plant/out:/tmp/openpilot/selfdrive/test/tests/plant/out
|
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/tests/plant && OPTEST=1 ./test_longitudinal.py'
|
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ fastcluster = "==1.1.25"
|
|||||||
backports-abc = "*"
|
backports-abc = "*"
|
||||||
pygame = "*"
|
pygame = "*"
|
||||||
simplejson = "*"
|
simplejson = "*"
|
||||||
|
python-logstash-async = "*"
|
||||||
|
pandas = "*"
|
||||||
|
seaborn = "*"
|
||||||
|
tensorflow-estimator = "==1.10.12"
|
||||||
|
pyproj = "*"
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
overpy = {git = "https://github.com/commaai/python-overpy.git",ref = "f86529af402d4642e1faeb146671c40284007323"}
|
overpy = {git = "https://github.com/commaai/python-overpy.git",ref = "f86529af402d4642e1faeb146671c40284007323"}
|
||||||
|
|||||||
Generated
+393
-316
File diff suppressed because it is too large
Load Diff
@@ -60,18 +60,18 @@ Supported Cars
|
|||||||
|
|
||||||
| Make | Model | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe |
|
| Make | Model | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe |
|
||||||
| ---------------------| -------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------|
|
| ---------------------| -------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------|
|
||||||
| Acura | ILX 2016-17 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 25mph | Nidec |
|
| Acura | ILX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 25mph | Nidec |
|
||||||
| Acura | RDX 2018 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
| Acura | RDX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||||
| Buick<sup>3</sup> | Regal 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| Buick<sup>3</sup> | Regal 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Chevrolet<sup>3</sup>| Malibu 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| Chevrolet<sup>3</sup>| Malibu 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Chevrolet<sup>3</sup>| Volt 2017-18 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| Chevrolet<sup>3</sup>| Volt 2017-18 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Cadillac<sup>3</sup> | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| Cadillac<sup>3</sup> | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Chrysler | Pacifica 2018 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
| Chrysler | Pacifica 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||||
| Chrysler | Pacifica Hybrid 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
| Chrysler | Pacifica Hybrid 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||||
| Chrysler | Pacifica Hybrid 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
| Chrysler | Pacifica Hybrid 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
||||||
| GMC<sup>3</sup> | Acadia Denali 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| GMC<sup>3</sup> | Acadia Denali 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Holden<sup>3</sup> | Astra 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
| Holden<sup>3</sup> | Astra 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>7</sup>|
|
||||||
| Honda | Accord 2018 | All | Yes | Stock | 0mph | 3mph | Bosch |
|
| Honda | Accord 2018-19 | All | Yes | Stock | 0mph | 3mph | Bosch |
|
||||||
| Honda | Civic Sedan/Coupe 2016-18| Honda Sensing | Yes | Yes | 0mph | 12mph | Nidec |
|
| Honda | Civic Sedan/Coupe 2016-18| Honda Sensing | Yes | Yes | 0mph | 12mph | Nidec |
|
||||||
| Honda | Civic Sedan/Coupe 2019 | Honda Sensing | Yes | Stock | 0mph | 2mph | Bosch |
|
| Honda | Civic Sedan/Coupe 2019 | Honda Sensing | Yes | Stock | 0mph | 2mph | Bosch |
|
||||||
| Honda | Civic Hatchback 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | Bosch |
|
| Honda | Civic Hatchback 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | Bosch |
|
||||||
@@ -84,9 +84,9 @@ Supported Cars
|
|||||||
| Honda | Pilot 2019 | All | Yes | Yes | 25mph<sup>1</sup>| 12mph | Inverted Nidec |
|
| Honda | Pilot 2019 | All | Yes | Yes | 25mph<sup>1</sup>| 12mph | Inverted Nidec |
|
||||||
| Honda | Ridgeline 2017-19 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
| Honda | Ridgeline 2017-19 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||||
| Hyundai | Santa Fe 2019 | All | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
| Hyundai | Santa Fe 2019 | All | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
||||||
| Hyundai | Elantra 2017 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom<sup>6</sup>|
|
| Hyundai | Elantra 2017-19 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom<sup>6</sup>|
|
||||||
| Hyundai | Genesis 2018 | All | Yes | Stock | 19mph | 34mph | Custom<sup>6</sup>|
|
| Hyundai | Genesis 2018 | All | Yes | Stock | 19mph | 34mph | Custom<sup>6</sup>|
|
||||||
| Jeep | Grand Cherokee 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
| Jeep | Grand Cherokee 2016-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||||
| Jeep | Grand Cherokee 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
| Jeep | Grand Cherokee 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
||||||
| Kia | Optima 2019 | SCC + LKAS | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
| Kia | Optima 2019 | SCC + LKAS | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
||||||
| Kia | Sorento 2018 | All | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
| Kia | Sorento 2018 | All | Yes | Stock | 0mph | 0mph | Custom<sup>6</sup>|
|
||||||
@@ -96,12 +96,13 @@ Supported Cars
|
|||||||
| Subaru | Crosstrek 2018 | EyeSight | Yes | Stock | 0mph | 0mph | Custom<sup>4</sup>|
|
| Subaru | Crosstrek 2018 | EyeSight | Yes | Stock | 0mph | 0mph | Custom<sup>4</sup>|
|
||||||
| Subaru | Impreza 2019 | EyeSight | Yes | Stock | 0mph | 0mph | Custom<sup>4</sup>|
|
| Subaru | Impreza 2019 | EyeSight | Yes | Stock | 0mph | 0mph | Custom<sup>4</sup>|
|
||||||
| Toyota | Avalon 2016 | TSS-P | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
| Toyota | Avalon 2016 | TSS-P | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||||
| Toyota | Camry 2018 | All | Yes | Stock | 0mph<sup>5</sup> | 0mph | Toyota |
|
| Toyota | Avalon 2017-18 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||||
| Toyota | C-HR 2017-18 | All | Yes | Stock | 0mph | 0mph | Toyota |
|
| Toyota | Camry 2018-19 | All | Yes | Stock | 0mph<sup>5</sup> | 0mph | Toyota |
|
||||||
|
| Toyota | C-HR 2017-19 | All | Yes | Stock | 0mph | 0mph | Toyota |
|
||||||
| Toyota | Corolla 2017-19 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
| Toyota | Corolla 2017-19 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||||
| Toyota | Corolla 2020 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
| Toyota | Corolla 2020 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||||
| Toyota | Corolla Hatchback 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
| Toyota | Corolla Hatchback 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||||
| Toyota | Highlander 2017-18 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
| Toyota | Highlander 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
| Toyota | Highlander Hybrid 2018 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
| Toyota | Highlander Hybrid 2018 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
| Toyota | Prius 2016 | TSS-P | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
| Toyota | Prius 2016 | TSS-P | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
| Toyota | Prius 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
| Toyota | Prius 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
@@ -110,6 +111,7 @@ Supported Cars
|
|||||||
| Toyota | Rav4 2017-18 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
| Toyota | Rav4 2017-18 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||||
| Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
| Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||||
| Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
| Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
|
| Toyota | Sienna 2018 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||||
|
|
||||||
<sup>1</sup>[Comma Pedal](https://community.comma.ai/wiki/index.php/Comma_Pedal) is used to provide stop-and-go capability to some of the openpilot-supported cars that don't currently support stop-and-go. Here is how to [build a Comma Pedal](https://medium.com/@jfrux/comma-pedal-building-with-macrofab-6328bea791e8). ***NOTE: The Comma Pedal is not officially supported by [comma.ai](https://comma.ai).*** <br />
|
<sup>1</sup>[Comma Pedal](https://community.comma.ai/wiki/index.php/Comma_Pedal) is used to provide stop-and-go capability to some of the openpilot-supported cars that don't currently support stop-and-go. Here is how to [build a Comma Pedal](https://medium.com/@jfrux/comma-pedal-building-with-macrofab-6328bea791e8). ***NOTE: The Comma Pedal is not officially supported by [comma.ai](https://comma.ai).*** <br />
|
||||||
<sup>2</sup>When disconnecting the Driver Support Unit (DSU), otherwise longitudinal control is stock ACC. For DSU locations, see [Toyota Wiki page](https://community.comma.ai/wiki/index.php/Toyota). <br />
|
<sup>2</sup>When disconnecting the Driver Support Unit (DSU), otherwise longitudinal control is stock ACC. For DSU locations, see [Toyota Wiki page](https://community.comma.ai/wiki/index.php/Toyota). <br />
|
||||||
|
|||||||
+19
@@ -1,3 +1,22 @@
|
|||||||
|
Version 0.6.2 (2019-07-29)
|
||||||
|
========================
|
||||||
|
* New driving model!
|
||||||
|
* Improve lane tracking with double lines
|
||||||
|
* Strongly improve stationary vehicle detection
|
||||||
|
* Strongly reduce cases of braking due to false leads
|
||||||
|
* Better lead tracking around turns
|
||||||
|
* Improve cut-in prediction by using neural network
|
||||||
|
* Improve lateral control on Toyota Camry and C-HR thanks to zorrobyte!
|
||||||
|
* Fix unintended openpilot disengagements on Jeep thanks to adhintz!
|
||||||
|
* Fix delayed transition to offroad when car is turned off
|
||||||
|
|
||||||
|
Version 0.6.1 (2019-07-21)
|
||||||
|
========================
|
||||||
|
* Remote SSH with comma prime and [ssh.comma.ai](https://ssh.comma.ai)
|
||||||
|
* Panda code Misra-c2012 compliance, tested against cppcheck coverage
|
||||||
|
* Lockout openpilot after 3 terminal alerts for driver distracted or unresponsive
|
||||||
|
* Toyota Sienna support thanks to wocsor!
|
||||||
|
|
||||||
Version 0.6 (2019-07-01)
|
Version 0.6 (2019-07-01)
|
||||||
========================
|
========================
|
||||||
* New model, with double the pixels and ten times the temporal context!
|
* New model, with double the pixels and ten times the temporal context!
|
||||||
|
|||||||
Binary file not shown.
@@ -76,6 +76,8 @@ struct CarEvent @0x9b1657f34caf3ad3 {
|
|||||||
controlsFailed @51;
|
controlsFailed @51;
|
||||||
sensorDataInvalid @52;
|
sensorDataInvalid @52;
|
||||||
commIssue @53;
|
commIssue @53;
|
||||||
|
tooDistracted @54;
|
||||||
|
posenetInvalid @55;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +324,7 @@ struct CarParams {
|
|||||||
lateralTuning :union {
|
lateralTuning :union {
|
||||||
pid @26 :LateralPIDTuning;
|
pid @26 :LateralPIDTuning;
|
||||||
indi @27 :LateralINDITuning;
|
indi @27 :LateralINDITuning;
|
||||||
|
lqr @40 :LateralLQRTuning;
|
||||||
}
|
}
|
||||||
|
|
||||||
steerLimitAlert @28 :Bool;
|
steerLimitAlert @28 :Bool;
|
||||||
@@ -337,6 +340,7 @@ struct CarParams {
|
|||||||
steerActuatorDelay @36 :Float32; # Steering wheel actuator delay in seconds
|
steerActuatorDelay @36 :Float32; # Steering wheel actuator delay in seconds
|
||||||
openpilotLongitudinalControl @37 :Bool; # is openpilot doing the longitudinal control?
|
openpilotLongitudinalControl @37 :Bool; # is openpilot doing the longitudinal control?
|
||||||
carVin @38 :Text; # VIN number queried during fingerprinting
|
carVin @38 :Text; # VIN number queried during fingerprinting
|
||||||
|
isPandaBlack @39: Bool;
|
||||||
|
|
||||||
struct LateralPIDTuning {
|
struct LateralPIDTuning {
|
||||||
kpBP @0 :List(Float32);
|
kpBP @0 :List(Float32);
|
||||||
@@ -363,6 +367,20 @@ struct CarParams {
|
|||||||
actuatorEffectiveness @3 :Float32;
|
actuatorEffectiveness @3 :Float32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LateralLQRTuning {
|
||||||
|
scale @0 :Float32;
|
||||||
|
ki @1 :Float32;
|
||||||
|
dcGain @2 :Float32;
|
||||||
|
|
||||||
|
# State space system
|
||||||
|
a @3 :List(Float32);
|
||||||
|
b @4 :List(Float32);
|
||||||
|
c @5 :List(Float32);
|
||||||
|
|
||||||
|
k @6 :List(Float32); # LQR gain
|
||||||
|
l @7 :List(Float32); # Kalman gain
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum SafetyModel {
|
enum SafetyModel {
|
||||||
# does NOT match board setting
|
# does NOT match board setting
|
||||||
|
|||||||
+45
-4
@@ -300,8 +300,20 @@ struct HealthData {
|
|||||||
started @2 :Bool;
|
started @2 :Bool;
|
||||||
controlsAllowed @3 :Bool;
|
controlsAllowed @3 :Bool;
|
||||||
gasInterceptorDetected @4 :Bool;
|
gasInterceptorDetected @4 :Bool;
|
||||||
startedSignalDetected @5 :Bool;
|
startedSignalDetectedDeprecated @5 :Bool;
|
||||||
isGreyPanda @6 :Bool;
|
hasGps @6 :Bool;
|
||||||
|
canSendErrs @7 :UInt32;
|
||||||
|
canFwdErrs @8 :UInt32;
|
||||||
|
gmlanSendErrs @9 :UInt32;
|
||||||
|
hwType @10: HwType;
|
||||||
|
|
||||||
|
enum HwType {
|
||||||
|
unknown @0;
|
||||||
|
whitePanda @1;
|
||||||
|
greyPanda @2;
|
||||||
|
blackPanda @3;
|
||||||
|
pedal @4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveUI {
|
struct LiveUI {
|
||||||
@@ -343,6 +355,8 @@ struct RadarState @0x9a185389d6fdd05f {
|
|||||||
fcw @10 :Bool;
|
fcw @10 :Bool;
|
||||||
status @11 :Bool;
|
status @11 :Bool;
|
||||||
aLeadTau @12 :Float32;
|
aLeadTau @12 :Float32;
|
||||||
|
modelProb @13 :Float32;
|
||||||
|
radar @14 :Bool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,6 +373,8 @@ struct LiveCalibrationData {
|
|||||||
# view_frame_from_road_frame
|
# view_frame_from_road_frame
|
||||||
# ui's is inversed needs new
|
# ui's is inversed needs new
|
||||||
extrinsicMatrix @4 :List(Float32);
|
extrinsicMatrix @4 :List(Float32);
|
||||||
|
# the direction of travel vector in device frame
|
||||||
|
rpyCalib @7 :List(Float32);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveTracks {
|
struct LiveTracks {
|
||||||
@@ -434,9 +450,12 @@ struct ControlsState @0x97ff69c53601abf1 {
|
|||||||
vCurvature @46 :Float32;
|
vCurvature @46 :Float32;
|
||||||
decelForTurn @47 :Bool;
|
decelForTurn @47 :Bool;
|
||||||
|
|
||||||
|
decelForModel @54 :Bool;
|
||||||
|
|
||||||
lateralControlState :union {
|
lateralControlState :union {
|
||||||
indiState @52 :LateralINDIState;
|
indiState @52 :LateralINDIState;
|
||||||
pidState @53 :LateralPIDState;
|
pidState @53 :LateralPIDState;
|
||||||
|
lqrState @55 :LateralLQRState;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OpenpilotState @0xdbe58b96d2d1ac61 {
|
enum OpenpilotState @0xdbe58b96d2d1ac61 {
|
||||||
@@ -491,6 +510,13 @@ struct ControlsState @0x97ff69c53601abf1 {
|
|||||||
saturated @8 :Bool;
|
saturated @8 :Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LateralLQRState {
|
||||||
|
active @0 :Bool;
|
||||||
|
steerAngle @1 :Float32;
|
||||||
|
i @2 :Float32;
|
||||||
|
output @3 :Float32;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveEventData {
|
struct LiveEventData {
|
||||||
@@ -508,6 +534,8 @@ struct ModelData {
|
|||||||
freePath @6 :List(Float32);
|
freePath @6 :List(Float32);
|
||||||
|
|
||||||
settings @5 :ModelSettings;
|
settings @5 :ModelSettings;
|
||||||
|
leadFuture @7 :LeadData;
|
||||||
|
speed @8 :List(Float32);
|
||||||
|
|
||||||
struct PathData {
|
struct PathData {
|
||||||
points @0 :List(Float32);
|
points @0 :List(Float32);
|
||||||
@@ -523,6 +551,10 @@ struct ModelData {
|
|||||||
std @2 :Float32;
|
std @2 :Float32;
|
||||||
relVel @3 :Float32;
|
relVel @3 :Float32;
|
||||||
relVelStd @4 :Float32;
|
relVelStd @4 :Float32;
|
||||||
|
relY @5 :Float32;
|
||||||
|
relYStd @6 :Float32;
|
||||||
|
relA @7 :Float32;
|
||||||
|
relAStd @8 :Float32;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModelSettings {
|
struct ModelSettings {
|
||||||
@@ -640,6 +672,7 @@ struct Plan {
|
|||||||
mpc1 @1;
|
mpc1 @1;
|
||||||
mpc2 @2;
|
mpc2 @2;
|
||||||
mpc3 @3;
|
mpc3 @3;
|
||||||
|
model @4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,6 +695,7 @@ struct PathPlan {
|
|||||||
angleOffset @11 :Float32;
|
angleOffset @11 :Float32;
|
||||||
sensorValid @14 :Bool;
|
sensorValid @14 :Bool;
|
||||||
commIssue @15 :Bool;
|
commIssue @15 :Bool;
|
||||||
|
posenetValid @16 :Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveLocationData {
|
struct LiveLocationData {
|
||||||
@@ -1640,8 +1674,13 @@ struct OrbKeyFrame {
|
|||||||
|
|
||||||
struct DriverMonitoring {
|
struct DriverMonitoring {
|
||||||
frameId @0 :UInt32;
|
frameId @0 :UInt32;
|
||||||
descriptor @1 :List(Float32);
|
descriptorDEPRECATED @1 :List(Float32);
|
||||||
std @2 :Float32;
|
stdDEPRECATED @2 :Float32;
|
||||||
|
faceOrientation @3 :List(Float32);
|
||||||
|
facePosition @4 :List(Float32);
|
||||||
|
faceProb @5 :Float32;
|
||||||
|
leftEyeProb @6 :Float32;
|
||||||
|
rightEyeProb @7 :Float32;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Boot {
|
struct Boot {
|
||||||
@@ -1659,6 +1698,8 @@ struct LiveParametersData {
|
|||||||
steerRatio @5 :Float32;
|
steerRatio @5 :Float32;
|
||||||
sensorValid @6 :Bool;
|
sensorValid @6 :Bool;
|
||||||
yawRate @7 :Float32;
|
yawRate @7 :Float32;
|
||||||
|
posenetSpeed @8 :Float32;
|
||||||
|
posenetValid @9 :Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveMapData {
|
struct LiveMapData {
|
||||||
|
|||||||
+16
-1
@@ -28,7 +28,7 @@ def get_tmpdir_on_same_filesystem(path):
|
|||||||
normpath = os.path.normpath(path)
|
normpath = os.path.normpath(path)
|
||||||
parts = normpath.split("/")
|
parts = normpath.split("/")
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
if parts[1].startswith("raid"):
|
if parts[1].startswith("raid") or parts[1].startswith("datasets"):
|
||||||
if len(parts) > 2 and parts[2] == "runner":
|
if len(parts) > 2 and parts[2] == "runner":
|
||||||
return "/{}/runner/tmp".format(parts[1])
|
return "/{}/runner/tmp".format(parts[1])
|
||||||
elif len(parts) > 2 and parts[2] == "aws":
|
elif len(parts) > 2 and parts[2] == "aws":
|
||||||
@@ -101,3 +101,18 @@ def atomic_write_in_dir(path, **kwargs):
|
|||||||
writer = AtomicWriter(path, **kwargs)
|
writer = AtomicWriter(path, **kwargs)
|
||||||
return writer._open(_get_fileobject_func(writer, os.path.dirname(path)))
|
return writer._open(_get_fileobject_func(writer, os.path.dirname(path)))
|
||||||
|
|
||||||
|
def atomic_write_in_dir_neos(path, contents, mode=None):
|
||||||
|
"""
|
||||||
|
Atomically writes contents to path using a temporary file in the same directory
|
||||||
|
as path. Useful on NEOS, where `os.link` (required by atomic_write_in_dir) is missing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
f = tempfile.NamedTemporaryFile(delete=False, prefix=".tmp", dir=os.path.dirname(path))
|
||||||
|
f.write(contents)
|
||||||
|
f.flush()
|
||||||
|
if mode is not None:
|
||||||
|
os.fchmod(f.fileno(), mode)
|
||||||
|
os.fsync(f.fileno())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
os.rename(f.name, path)
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ _DEBUG_ADDRESS = {1880: 8} # reserved for debug purposes
|
|||||||
|
|
||||||
def is_valid_for_fingerprint(msg, car_fingerprint):
|
def is_valid_for_fingerprint(msg, car_fingerprint):
|
||||||
adr = msg.address
|
adr = msg.address
|
||||||
bus = msg.src
|
|
||||||
# ignore addresses that are more than 11 bits
|
# ignore addresses that are more than 11 bits
|
||||||
return (adr in car_fingerprint and car_fingerprint[adr] == len(msg.dat)) or \
|
return (adr in car_fingerprint and car_fingerprint[adr] == len(msg.dat)) or adr >= 0x800
|
||||||
bus != 0 or adr >= 0x800
|
|
||||||
|
|
||||||
|
|
||||||
def eliminate_incompatible_cars(msg, candidate_cars):
|
def eliminate_incompatible_cars(msg, candidate_cars):
|
||||||
|
|||||||
@@ -1,253 +0,0 @@
|
|||||||
# pylint: skip-file
|
|
||||||
from __future__ import print_function
|
|
||||||
import abc
|
|
||||||
import numpy as np
|
|
||||||
# The EKF class contains the framework for an Extended Kalman Filter, but must be subclassed to use.
|
|
||||||
# A subclass must implement:
|
|
||||||
# 1) calc_transfer_fun(); see bottom of file for more info.
|
|
||||||
# 2) __init__() to initialize self.state, self.covar, and self.process_noise appropriately
|
|
||||||
|
|
||||||
# Alternatively, the existing implementations of EKF can be used (e.g. EKF2D)
|
|
||||||
|
|
||||||
# Sensor classes are optionally used to pass measurement information into the EKF, to keep
|
|
||||||
# sensor parameters and processing methods for a each sensor together.
|
|
||||||
# Sensor classes have a read() method which takes raw sensor data and returns
|
|
||||||
# a SensorReading object, which can be passed to the EKF update() method.
|
|
||||||
|
|
||||||
# For usage, see run_ekf1d.py in selfdrive/new for a simple example.
|
|
||||||
# ekf.predict(dt) should be called between update cycles with the time since it was last called.
|
|
||||||
# Ideally, predict(dt) should be called at a relatively constant rate.
|
|
||||||
# update() should be called once per sensor, and can be called multiple times between predict steps.
|
|
||||||
# Access and set the state of the filter directly with ekf.state and ekf.covar.
|
|
||||||
|
|
||||||
|
|
||||||
class SensorReading:
|
|
||||||
# Given a perfect model and no noise, data = obs_model * state
|
|
||||||
def __init__(self, data, covar, obs_model):
|
|
||||||
self.data = data
|
|
||||||
self.obs_model = obs_model
|
|
||||||
self.covar = covar
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "SensorReading(data={}, covar={}, obs_model={})".format(
|
|
||||||
repr(self.data), repr(self.covar), repr(self.obs_model))
|
|
||||||
|
|
||||||
|
|
||||||
# A generic sensor class that does no pre-processing of data
|
|
||||||
class SimpleSensor:
|
|
||||||
# obs_model can be
|
|
||||||
# a full observation model matrix, or
|
|
||||||
# an integer or tuple of indices into ekf.state, indicating which variables are being directly observed
|
|
||||||
# covar can be
|
|
||||||
# a full covariance matrix
|
|
||||||
# a float or tuple of individual covars for each component of the sensor reading
|
|
||||||
# dims is the number of states in the EKF
|
|
||||||
def __init__(self, obs_model, covar, dims):
|
|
||||||
# Allow for integer covar/obs_model
|
|
||||||
if not hasattr(obs_model, "__len__"):
|
|
||||||
obs_model = (obs_model, )
|
|
||||||
if not hasattr(covar, "__len__"):
|
|
||||||
covar = (covar, )
|
|
||||||
|
|
||||||
# Full observation model passed
|
|
||||||
if dims in np.array(obs_model).shape:
|
|
||||||
self.obs_model = np.asmatrix(obs_model)
|
|
||||||
self.covar = np.asmatrix(covar)
|
|
||||||
# Indices of unit observations passed
|
|
||||||
else:
|
|
||||||
self.obs_model = np.matlib.zeros((len(obs_model), dims))
|
|
||||||
self.obs_model[:, list(obs_model)] = np.identity(len(obs_model))
|
|
||||||
if np.asarray(covar).ndim == 2:
|
|
||||||
self.covar = np.asmatrix(covar)
|
|
||||||
elif len(covar) == len(obs_model):
|
|
||||||
self.covar = np.matlib.diag(covar)
|
|
||||||
else:
|
|
||||||
self.covar = np.matlib.identity(len(obs_model)) * covar
|
|
||||||
|
|
||||||
def read(self, data, covar=None):
|
|
||||||
if covar:
|
|
||||||
self.covar = covar
|
|
||||||
return SensorReading(data, self.covar, self.obs_model)
|
|
||||||
|
|
||||||
|
|
||||||
class EKF:
|
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
|
|
||||||
def __init__(self, debug=False):
|
|
||||||
self.DEBUG = debug
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "EKF(state={}, covar={})".format(self.state, self.covar)
|
|
||||||
|
|
||||||
# Measurement update
|
|
||||||
# Reading should be a SensorReading object with data, covar, and obs_model attributes
|
|
||||||
def update(self, reading):
|
|
||||||
# Potential improvements:
|
|
||||||
# deal with negative covars
|
|
||||||
# add noise to really low covars to ensure stability
|
|
||||||
# use mahalanobis distance to reject outliers
|
|
||||||
# wrap angles after state updates and innovation
|
|
||||||
|
|
||||||
# y = z - H*x
|
|
||||||
innovation = reading.data - reading.obs_model * self.state
|
|
||||||
|
|
||||||
if self.DEBUG:
|
|
||||||
print("reading:\n",reading.data)
|
|
||||||
print("innovation:\n",innovation)
|
|
||||||
|
|
||||||
# S = H*P*H' + R
|
|
||||||
innovation_covar = reading.obs_model * self.covar * reading.obs_model.T + reading.covar
|
|
||||||
|
|
||||||
# K = P*H'*S^-1
|
|
||||||
kalman_gain = self.covar * reading.obs_model.T * np.linalg.inv(
|
|
||||||
innovation_covar)
|
|
||||||
|
|
||||||
if self.DEBUG:
|
|
||||||
print("gain:\n", kalman_gain)
|
|
||||||
print("innovation_covar:\n", innovation_covar)
|
|
||||||
print("innovation: ", innovation)
|
|
||||||
print("test: ", self.covar * reading.obs_model.T * (
|
|
||||||
reading.obs_model * self.covar * reading.obs_model.T + reading.covar *
|
|
||||||
0).I)
|
|
||||||
|
|
||||||
# x = x + K*y
|
|
||||||
self.state += kalman_gain*innovation
|
|
||||||
|
|
||||||
# print "covar", np.diag(self.covar)
|
|
||||||
#self.state[(roll_vel, yaw_vel, pitch_vel),:] = reading.data
|
|
||||||
|
|
||||||
# Standard form: P = (I - K*H)*P
|
|
||||||
# self.covar = (self.identity - kalman_gain*reading.obs_model) * self.covar
|
|
||||||
|
|
||||||
# Use the Joseph form for numerical stability: P = (I-K*H)*P*(I - K*H)' + K*R*K'
|
|
||||||
aux_mtrx = (self.identity - kalman_gain * reading.obs_model)
|
|
||||||
self.covar = aux_mtrx * self.covar * aux_mtrx.T + kalman_gain * reading.covar * kalman_gain.T
|
|
||||||
|
|
||||||
if self.DEBUG:
|
|
||||||
print("After update")
|
|
||||||
print("state\n", self.state)
|
|
||||||
print("covar:\n",self.covar)
|
|
||||||
|
|
||||||
def update_scalar(self, reading):
|
|
||||||
# like update but knowing that measurement is a scalar
|
|
||||||
# this avoids matrix inversions and speeds up (surprisingly) drived.py a lot
|
|
||||||
|
|
||||||
# innovation = reading.data - np.matmul(reading.obs_model, self.state)
|
|
||||||
# innovation_covar = np.matmul(np.matmul(reading.obs_model, self.covar), reading.obs_model.T) + reading.covar
|
|
||||||
# kalman_gain = np.matmul(self.covar, reading.obs_model.T)/innovation_covar
|
|
||||||
# self.state += np.matmul(kalman_gain, innovation)
|
|
||||||
# aux_mtrx = self.identity - np.matmul(kalman_gain, reading.obs_model)
|
|
||||||
# self.covar = np.matmul(aux_mtrx, np.matmul(self.covar, aux_mtrx.T)) + np.matmul(kalman_gain, np.matmul(reading.covar, kalman_gain.T))
|
|
||||||
|
|
||||||
# written without np.matmul
|
|
||||||
es = np.einsum
|
|
||||||
ABC_T = "ij,jk,lk->il"
|
|
||||||
AB_T = "ij,kj->ik"
|
|
||||||
AB = "ij,jk->ik"
|
|
||||||
innovation = reading.data - es(AB, reading.obs_model, self.state)
|
|
||||||
innovation_covar = es(ABC_T, reading.obs_model, self.covar,
|
|
||||||
reading.obs_model) + reading.covar
|
|
||||||
kalman_gain = es(AB_T, self.covar, reading.obs_model) / innovation_covar
|
|
||||||
|
|
||||||
self.state += es(AB, kalman_gain, innovation)
|
|
||||||
aux_mtrx = self.identity - es(AB, kalman_gain, reading.obs_model)
|
|
||||||
self.covar = es(ABC_T, aux_mtrx, self.covar, aux_mtrx) + \
|
|
||||||
es(ABC_T, kalman_gain, reading.covar, kalman_gain)
|
|
||||||
|
|
||||||
# Prediction update
|
|
||||||
def predict(self, dt):
|
|
||||||
es = np.einsum
|
|
||||||
ABC_T = "ij,jk,lk->il"
|
|
||||||
AB = "ij,jk->ik"
|
|
||||||
|
|
||||||
# State update
|
|
||||||
transfer_fun, transfer_fun_jacobian = self.calc_transfer_fun(dt)
|
|
||||||
|
|
||||||
# self.state = np.matmul(transfer_fun, self.state)
|
|
||||||
# self.covar = np.matmul(np.matmul(transfer_fun_jacobian, self.covar), transfer_fun_jacobian.T) + self.process_noise * dt
|
|
||||||
|
|
||||||
# x = f(x, u), written in the form x = A(x, u)*x
|
|
||||||
self.state = es(AB, transfer_fun, self.state)
|
|
||||||
|
|
||||||
# P = J*P*J' + Q
|
|
||||||
self.covar = es(ABC_T, transfer_fun_jacobian, self.covar,
|
|
||||||
transfer_fun_jacobian) + self.process_noise * dt #!dt
|
|
||||||
|
|
||||||
#! Clip covariance to avoid explosions
|
|
||||||
self.covar = np.clip(self.covar,-1e10,1e10)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def calc_transfer_fun(self, dt):
|
|
||||||
"""Return a tuple with the transfer function and transfer function jacobian
|
|
||||||
The transfer function and jacobian should both be a numpy matrix of size DIMSxDIMS
|
|
||||||
|
|
||||||
The transfer function matrix A should satisfy the state-update equation
|
|
||||||
x_(k+1) = A * x_k
|
|
||||||
|
|
||||||
The jacobian J is the direct jacobian A*x_k. For linear systems J=A.
|
|
||||||
|
|
||||||
Current implementations calculate A and J as functions of state. Control input
|
|
||||||
can be added trivially by adding a control parameter to predict() and calc_tranfer_update(),
|
|
||||||
and using it during calculation of A and J
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class FastEKF1D(EKF):
|
|
||||||
"""Fast version of EKF for 1D problems with scalar readings."""
|
|
||||||
|
|
||||||
def __init__(self, dt, var_init, Q):
|
|
||||||
super(FastEKF1D, self).__init__(False)
|
|
||||||
self.state = [0, 0]
|
|
||||||
self.covar = [var_init, var_init, 0]
|
|
||||||
|
|
||||||
# Process Noise
|
|
||||||
self.dtQ0 = dt * Q[0]
|
|
||||||
self.dtQ1 = dt * Q[1]
|
|
||||||
|
|
||||||
def update(self, reading):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def update_scalar(self, reading):
|
|
||||||
# TODO(mgraczyk): Delete this for speed.
|
|
||||||
# assert np.all(reading.obs_model == [1, 0])
|
|
||||||
|
|
||||||
rcov = reading.covar[0, 0]
|
|
||||||
|
|
||||||
x = self.state
|
|
||||||
S = self.covar
|
|
||||||
|
|
||||||
innovation = reading.data - x[0]
|
|
||||||
innovation_covar = S[0] + rcov
|
|
||||||
|
|
||||||
k0 = S[0] / innovation_covar
|
|
||||||
k1 = S[2] / innovation_covar
|
|
||||||
|
|
||||||
x[0] += k0 * innovation
|
|
||||||
x[1] += k1 * innovation
|
|
||||||
|
|
||||||
mk = 1 - k0
|
|
||||||
S[1] += k1 * (k1 * (S[0] + rcov) - 2 * S[2])
|
|
||||||
S[2] = mk * (S[2] - k1 * S[0]) + rcov * k0 * k1
|
|
||||||
S[0] = mk * mk * S[0] + rcov * k0 * k0
|
|
||||||
|
|
||||||
def predict(self, dt):
|
|
||||||
# State update
|
|
||||||
x = self.state
|
|
||||||
|
|
||||||
x[0] += dt * x[1]
|
|
||||||
|
|
||||||
# P = J*P*J' + Q
|
|
||||||
S = self.covar
|
|
||||||
S[0] += dt * (2 * S[2] + dt * S[1]) + self.dtQ0
|
|
||||||
S[2] += dt * S[1]
|
|
||||||
S[1] += self.dtQ1
|
|
||||||
|
|
||||||
# Clip covariance to avoid explosions
|
|
||||||
S = max(-1e10, min(S, 1e10))
|
|
||||||
|
|
||||||
def calc_transfer_fun(self, dt):
|
|
||||||
tf = np.identity(2)
|
|
||||||
tf[0, 1] = dt
|
|
||||||
tfj = tf
|
|
||||||
return tf, tfj
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
import numpy.matlib
|
|
||||||
import unittest
|
|
||||||
import timeit
|
|
||||||
|
|
||||||
from common.kalman.ekf import EKF, SimpleSensor, FastEKF1D
|
|
||||||
|
|
||||||
class TestEKF(EKF):
|
|
||||||
def __init__(self, var_init, Q):
|
|
||||||
super(TestEKF, self).__init__(False)
|
|
||||||
self.identity = numpy.matlib.identity(2)
|
|
||||||
self.state = numpy.matlib.zeros((2, 1))
|
|
||||||
self.covar = self.identity * var_init
|
|
||||||
|
|
||||||
self.process_noise = numpy.matlib.diag(Q)
|
|
||||||
|
|
||||||
def calc_transfer_fun(self, dt):
|
|
||||||
tf = numpy.matlib.identity(2)
|
|
||||||
tf[0, 1] = dt
|
|
||||||
return tf, tf
|
|
||||||
|
|
||||||
|
|
||||||
class EKFTest(unittest.TestCase):
|
|
||||||
def test_update_scalar(self):
|
|
||||||
ekf = TestEKF(1e3, [0.1, 1])
|
|
||||||
dt = 1. / 100
|
|
||||||
|
|
||||||
sensor = SimpleSensor(0, 1, 2)
|
|
||||||
readings = map(sensor.read, np.arange(100, 300))
|
|
||||||
|
|
||||||
for reading in readings:
|
|
||||||
ekf.update_scalar(reading)
|
|
||||||
ekf.predict(dt)
|
|
||||||
|
|
||||||
np.testing.assert_allclose(ekf.state, [[300], [100]], 1e-4)
|
|
||||||
np.testing.assert_allclose(
|
|
||||||
ekf.covar,
|
|
||||||
np.asarray([[0.0563, 0.10278], [0.10278, 0.55779]]),
|
|
||||||
atol=1e-4)
|
|
||||||
|
|
||||||
def test_unbiased(self):
|
|
||||||
ekf = TestEKF(1e3, [0., 0.])
|
|
||||||
dt = np.float64(1. / 100)
|
|
||||||
|
|
||||||
sensor = SimpleSensor(0, 1, 2)
|
|
||||||
readings = map(sensor.read, np.arange(1000))
|
|
||||||
|
|
||||||
for reading in readings:
|
|
||||||
ekf.update_scalar(reading)
|
|
||||||
ekf.predict(dt)
|
|
||||||
|
|
||||||
np.testing.assert_allclose(ekf.state, [[1000.], [100.]], 1e-4)
|
|
||||||
|
|
||||||
|
|
||||||
class FastEKF1DTest(unittest.TestCase):
|
|
||||||
def test_correctness(self):
|
|
||||||
dt = 1. / 100
|
|
||||||
reading = SimpleSensor(0, 1, 2).read(100)
|
|
||||||
|
|
||||||
ekf = TestEKF(1e3, [0.1, 1])
|
|
||||||
fast_ekf = FastEKF1D(dt, 1e3, [0.1, 1])
|
|
||||||
|
|
||||||
ekf.update_scalar(reading)
|
|
||||||
fast_ekf.update_scalar(reading)
|
|
||||||
self.assertAlmostEqual(ekf.state[0] , fast_ekf.state[0])
|
|
||||||
self.assertAlmostEqual(ekf.state[1] , fast_ekf.state[1])
|
|
||||||
self.assertAlmostEqual(ekf.covar[0, 0], fast_ekf.covar[0])
|
|
||||||
self.assertAlmostEqual(ekf.covar[0, 1], fast_ekf.covar[2])
|
|
||||||
self.assertAlmostEqual(ekf.covar[1, 1], fast_ekf.covar[1])
|
|
||||||
|
|
||||||
ekf.predict(dt)
|
|
||||||
fast_ekf.predict(dt)
|
|
||||||
self.assertAlmostEqual(ekf.state[0] , fast_ekf.state[0])
|
|
||||||
self.assertAlmostEqual(ekf.state[1] , fast_ekf.state[1])
|
|
||||||
self.assertAlmostEqual(ekf.covar[0, 0], fast_ekf.covar[0])
|
|
||||||
self.assertAlmostEqual(ekf.covar[0, 1], fast_ekf.covar[2])
|
|
||||||
self.assertAlmostEqual(ekf.covar[1, 1], fast_ekf.covar[1])
|
|
||||||
|
|
||||||
def test_speed(self):
|
|
||||||
setup = """
|
|
||||||
import numpy as np
|
|
||||||
from common.kalman.tests.test_ekf import TestEKF
|
|
||||||
from common.kalman.ekf import SimpleSensor, FastEKF1D
|
|
||||||
|
|
||||||
dt = 1. / 100
|
|
||||||
reading = SimpleSensor(0, 1, 2).read(100)
|
|
||||||
|
|
||||||
var_init, Q = 1e3, [0.1, 1]
|
|
||||||
ekf = TestEKF(var_init, Q)
|
|
||||||
fast_ekf = FastEKF1D(dt, var_init, Q)
|
|
||||||
"""
|
|
||||||
|
|
||||||
timeit.timeit("""
|
|
||||||
ekf.update_scalar(reading)
|
|
||||||
ekf.predict(dt)
|
|
||||||
""", setup=setup, number=1000)
|
|
||||||
|
|
||||||
ekf_speed = timeit.timeit("""
|
|
||||||
ekf.update_scalar(reading)
|
|
||||||
ekf.predict(dt)
|
|
||||||
""", setup=setup, number=20000)
|
|
||||||
|
|
||||||
timeit.timeit("""
|
|
||||||
fast_ekf.update_scalar(reading)
|
|
||||||
fast_ekf.predict(dt)
|
|
||||||
""", setup=setup, number=1000)
|
|
||||||
|
|
||||||
fast_ekf_speed = timeit.timeit("""
|
|
||||||
fast_ekf.update_scalar(reading)
|
|
||||||
fast_ekf.predict(dt)
|
|
||||||
""", setup=setup, number=20000)
|
|
||||||
|
|
||||||
assert fast_ekf_speed < ekf_speed / 4
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
@@ -50,12 +50,15 @@ class UnknownKeyName(Exception):
|
|||||||
|
|
||||||
keys = {
|
keys = {
|
||||||
"AccessToken": [TxType.PERSISTENT],
|
"AccessToken": [TxType.PERSISTENT],
|
||||||
|
"AthenadPid": [TxType.PERSISTENT],
|
||||||
"CalibrationParams": [TxType.PERSISTENT],
|
"CalibrationParams": [TxType.PERSISTENT],
|
||||||
"CarParams": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
"CarParams": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||||
|
"CarVin": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||||
"CompletedTrainingVersion": [TxType.PERSISTENT],
|
"CompletedTrainingVersion": [TxType.PERSISTENT],
|
||||||
"ControlsParams": [TxType.PERSISTENT],
|
"ControlsParams": [TxType.PERSISTENT],
|
||||||
"DoUninstall": [TxType.CLEAR_ON_MANAGER_START],
|
"DoUninstall": [TxType.CLEAR_ON_MANAGER_START],
|
||||||
"DongleId": [TxType.PERSISTENT],
|
"DongleId": [TxType.PERSISTENT],
|
||||||
|
"GithubSshKeys": [TxType.PERSISTENT],
|
||||||
"GitBranch": [TxType.PERSISTENT],
|
"GitBranch": [TxType.PERSISTENT],
|
||||||
"GitCommit": [TxType.PERSISTENT],
|
"GitCommit": [TxType.PERSISTENT],
|
||||||
"GitRemote": [TxType.PERSISTENT],
|
"GitRemote": [TxType.PERSISTENT],
|
||||||
@@ -68,6 +71,7 @@ keys = {
|
|||||||
"IsUploadRawEnabled": [TxType.PERSISTENT],
|
"IsUploadRawEnabled": [TxType.PERSISTENT],
|
||||||
"IsUploadVideoOverCellularEnabled": [TxType.PERSISTENT],
|
"IsUploadVideoOverCellularEnabled": [TxType.PERSISTENT],
|
||||||
"LimitSetSpeed": [TxType.PERSISTENT],
|
"LimitSetSpeed": [TxType.PERSISTENT],
|
||||||
|
"LimitSetSpeedNeural": [TxType.PERSISTENT],
|
||||||
"LiveParameters": [TxType.PERSISTENT],
|
"LiveParameters": [TxType.PERSISTENT],
|
||||||
"LongitudinalControl": [TxType.PERSISTENT],
|
"LongitudinalControl": [TxType.PERSISTENT],
|
||||||
"Passive": [TxType.PERSISTENT],
|
"Passive": [TxType.PERSISTENT],
|
||||||
@@ -75,6 +79,7 @@ keys = {
|
|||||||
"ShouldDoUpdate": [TxType.CLEAR_ON_MANAGER_START],
|
"ShouldDoUpdate": [TxType.CLEAR_ON_MANAGER_START],
|
||||||
"SpeedLimitOffset": [TxType.PERSISTENT],
|
"SpeedLimitOffset": [TxType.PERSISTENT],
|
||||||
"SubscriberInfo": [TxType.PERSISTENT],
|
"SubscriberInfo": [TxType.PERSISTENT],
|
||||||
|
"TermsVersion": [TxType.PERSISTENT],
|
||||||
"TrainingVersion": [TxType.PERSISTENT],
|
"TrainingVersion": [TxType.PERSISTENT],
|
||||||
"Version": [TxType.PERSISTENT],
|
"Version": [TxType.PERSISTENT],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ DT_CTRL = 0.01 # controlsd
|
|||||||
DT_PLAN = 0.05 # mpc
|
DT_PLAN = 0.05 # mpc
|
||||||
DT_MDL = 0.05 # model
|
DT_MDL = 0.05 # model
|
||||||
DT_DMON = 0.1 # driver monitoring
|
DT_DMON = 0.1 # driver monitoring
|
||||||
|
DT_TRML = 0.5 # thermald and manager
|
||||||
|
|
||||||
|
|
||||||
ffi = FFI()
|
ffi = FFI()
|
||||||
|
|||||||
+68
-62
@@ -1,61 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import time
|
|
||||||
from common.realtime import sec_since_boot
|
|
||||||
import selfdrive.messaging as messaging
|
import selfdrive.messaging as messaging
|
||||||
from selfdrive.boardd.boardd import can_list_to_can_capnp
|
from selfdrive.boardd.boardd import can_list_to_can_capnp
|
||||||
|
|
||||||
def get_vin(logcan, sendcan):
|
VIN_UNKNOWN = "0" * 17
|
||||||
|
|
||||||
# works on standard 11-bit addresses for diagnostic. Tested on Toyota and Subaru;
|
|
||||||
# Honda uses the extended 29-bit addresses, and unfortunately only works from OBDII
|
|
||||||
query_msg = [[0x7df, 0, '\x02\x09\x02'.ljust(8, "\x00"), 0],
|
|
||||||
[0x7e0, 0, '\x30'.ljust(8, "\x00"), 0]]
|
|
||||||
|
|
||||||
cnts = [1, 2] # Number of messages to wait for at each iteration
|
|
||||||
vin_valid = True
|
|
||||||
|
|
||||||
dat = []
|
|
||||||
for i in range(len(query_msg)):
|
|
||||||
cnt = 0
|
|
||||||
sendcan.send(can_list_to_can_capnp([query_msg[i]], msgtype='sendcan'))
|
|
||||||
got_response = False
|
|
||||||
t_start = sec_since_boot()
|
|
||||||
while sec_since_boot() - t_start < 0.05 and not got_response:
|
|
||||||
for a in messaging.drain_sock(logcan):
|
|
||||||
for can in a.can:
|
|
||||||
if can.src == 0 and can.address == 0x7e8:
|
|
||||||
vin_valid = vin_valid and is_vin_response_valid(can.dat, i, cnt)
|
|
||||||
dat += can.dat[2:] if i == 0 else can.dat[1:]
|
|
||||||
cnt += 1
|
|
||||||
if cnt == cnts[i]:
|
|
||||||
got_response = True
|
|
||||||
time.sleep(0.01)
|
|
||||||
|
|
||||||
return "".join(dat[3:]) if vin_valid else ""
|
|
||||||
|
|
||||||
"""
|
|
||||||
if 'vin' not in gctx:
|
|
||||||
print "getting vin"
|
|
||||||
gctx['vin'] = query_vin()[3:]
|
|
||||||
print "got VIN %s" % (gctx['vin'],)
|
|
||||||
cloudlog.info("got VIN %s" % (gctx['vin'],))
|
|
||||||
|
|
||||||
# *** determine platform based on VIN ****
|
|
||||||
if vin.startswith("19UDE2F36G"):
|
|
||||||
print "ACURA ILX 2016"
|
|
||||||
self.civic = False
|
|
||||||
else:
|
|
||||||
# TODO: add Honda check explicitly
|
|
||||||
print "HONDA CIVIC 2016"
|
|
||||||
self.civic = True
|
|
||||||
|
|
||||||
# *** special case VIN of Acura test platform
|
|
||||||
if vin == "19UDE2F36GA001322":
|
|
||||||
print "comma.ai test platform detected"
|
|
||||||
# it has a gas interceptor and a torque mod
|
|
||||||
self.torque_mod = True
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
# sanity checks on response messages from vin query
|
# sanity checks on response messages from vin query
|
||||||
def is_vin_response_valid(can_dat, step, cnt):
|
def is_vin_response_valid(can_dat, step, cnt):
|
||||||
@@ -84,12 +31,71 @@ def is_vin_response_valid(can_dat, step, cnt):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
class VinQuery():
|
||||||
import zmq
|
def __init__(self, bus):
|
||||||
from selfdrive.services import service_list
|
self.bus = bus
|
||||||
context = zmq.Context()
|
# works on standard 11-bit addresses for diagnostic. Tested on Toyota and Subaru;
|
||||||
logcan = messaging.sub_sock(context, service_list['can'].port)
|
# Honda uses the extended 29-bit addresses, and unfortunately only works from OBDII
|
||||||
sendcan = messaging.pub_sock(context, service_list['sendcan'].port)
|
self.query_ext_msgs = [[0x18DB33F1, 0, '\x02\x09\x02'.ljust(8, "\x00"), bus],
|
||||||
time.sleep(1.) # give time to sendcan socket to start
|
[0x18DA10f1, 0, '\x30'.ljust(8, "\x00"), bus]]
|
||||||
|
self.query_nor_msgs = [[0x7df, 0, '\x02\x09\x02'.ljust(8, "\x00"), bus],
|
||||||
|
[0x7e0, 0, '\x30'.ljust(8, "\x00"), bus]]
|
||||||
|
|
||||||
print get_vin(logcan, sendcan)
|
self.cnts = [1, 2] # number of messages to wait for at each iteration
|
||||||
|
self.step = 0
|
||||||
|
self.cnt = 0
|
||||||
|
self.responded = False
|
||||||
|
self.never_responded = True
|
||||||
|
self.dat = []
|
||||||
|
self.vin = VIN_UNKNOWN
|
||||||
|
|
||||||
|
def check_response(self, msg):
|
||||||
|
# have we got a VIN query response?
|
||||||
|
if msg.src == self.bus and msg.address in [0x18daf110, 0x7e8]:
|
||||||
|
self.never_responded = False
|
||||||
|
# basic sanity checks on ISO-TP response
|
||||||
|
if is_vin_response_valid(msg.dat, self.step, self.cnt):
|
||||||
|
self.dat += msg.dat[2:] if self.step == 0 else msg.dat[1:]
|
||||||
|
self.cnt += 1
|
||||||
|
if self.cnt == self.cnts[self.step]:
|
||||||
|
self.responded = True
|
||||||
|
self.step += 1
|
||||||
|
|
||||||
|
def send_query(self, sendcan):
|
||||||
|
# keep sending VIN qury if ECU isn't responsing.
|
||||||
|
# sendcan is probably not ready due to the zmq slow joiner syndrome
|
||||||
|
if self.never_responded or (self.responded and self.step < len(self.cnts)):
|
||||||
|
sendcan.send(can_list_to_can_capnp([self.query_ext_msgs[self.step]], msgtype='sendcan'))
|
||||||
|
sendcan.send(can_list_to_can_capnp([self.query_nor_msgs[self.step]], msgtype='sendcan'))
|
||||||
|
self.responded = False
|
||||||
|
self.cnt = 0
|
||||||
|
|
||||||
|
def get_vin(self):
|
||||||
|
# only report vin if procedure is finished
|
||||||
|
if self.step == len(self.cnts) and self.cnt == self.cnts[-1]:
|
||||||
|
self.vin = "".join(self.dat[3:])
|
||||||
|
return self.vin
|
||||||
|
|
||||||
|
|
||||||
|
def get_vin(logcan, sendcan, bus, query_time=1.):
|
||||||
|
vin_query = VinQuery(bus)
|
||||||
|
frame = 0
|
||||||
|
|
||||||
|
# 1s max of VIN query time
|
||||||
|
while frame < query_time * 100:
|
||||||
|
a = messaging.recv_one(logcan)
|
||||||
|
|
||||||
|
for can in a.can:
|
||||||
|
vin_query.check_response(can)
|
||||||
|
|
||||||
|
vin_query.send_query(sendcan)
|
||||||
|
frame += 1
|
||||||
|
|
||||||
|
return vin_query.get_vin()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from selfdrive.services import service_list
|
||||||
|
logcan = messaging.sub_sock(service_list['can'].port)
|
||||||
|
sendcan = messaging.pub_sock(service_list['sendcan'].port)
|
||||||
|
print get_vin(logcan, sendcan, 0)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -262,7 +262,7 @@ BO_ 300 NEW_MSG_12C: 8 XXX
|
|||||||
|
|
||||||
BO_ 308 ACCEL_GAS_134: 8 XXX
|
BO_ 308 ACCEL_GAS_134: 8 XXX
|
||||||
SG_ COUNTER : 55|4@0+ (1,0) [0|15] "" XXX
|
SG_ COUNTER : 55|4@0+ (1,0) [0|15] "" XXX
|
||||||
SG_ ACCEL_134 : 43|4@0+ (1,0) [0|15] "" XXX
|
SG_ ACCEL_134 : 46|7@0+ (1,0) [0|127] "" XXX
|
||||||
|
|
||||||
BO_ 532 ENERGY_RELATED_214: 8 XXX
|
BO_ 532 ENERGY_RELATED_214: 8 XXX
|
||||||
SG_ NOISY_SLOWLY_DECREASING : 16|9@0+ (1,0) [0|255] "" XXX
|
SG_ NOISY_SLOWLY_DECREASING : 16|9@0+ (1,0) [0|255] "" XXX
|
||||||
@@ -413,6 +413,7 @@ CM_ SG_ 825 BEEP_339 "sent every 0.5s. 0050 is no beep. To beep send 4355 or 415
|
|||||||
CM_ SG_ 270 ELECTRIC_MOTOR "0x7fff indicates electric motor not in use";
|
CM_ SG_ 270 ELECTRIC_MOTOR "0x7fff indicates electric motor not in use";
|
||||||
CM_ SG_ 291 ENERGY_GAIN_LOSS "unsure what this actually is";
|
CM_ SG_ 291 ENERGY_GAIN_LOSS "unsure what this actually is";
|
||||||
CM_ SG_ 291 ENERGY_SMOOTHER_CURVE "unusre what it is, but smoother";
|
CM_ SG_ 291 ENERGY_SMOOTHER_CURVE "unusre what it is, but smoother";
|
||||||
|
CM_ SG_ 308 ACCEL_134 "only set when human presses accel pedal";
|
||||||
CM_ SG_ 532 NOISY_SLOWLY_DECREASING "perhaps battery but do not know";
|
CM_ SG_ 532 NOISY_SLOWLY_DECREASING "perhaps battery but do not know";
|
||||||
CM_ SG_ 816 TRACTION_OFF "set when traction off button is enabled";
|
CM_ SG_ 816 TRACTION_OFF "set when traction off button is enabled";
|
||||||
CM_ SG_ 816 TOGGLE_PARKSENSE "sending 3000071ec0ff9000 enables or disables parksense";
|
CM_ SG_ 816 TOGGLE_PARKSENSE "sending 3000071ec0ff9000 enables or disables parksense";
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
CM_ "IMPORT _toyota_2017.dbc"
|
||||||
|
CM_ "IMPORT _comma.dbc"
|
||||||
|
|
||||||
|
BO_ 550 BRAKE_MODULE: 8 XXX
|
||||||
|
SG_ BRAKE_PRESSURE : 0|9@0+ (1,0) [0|511] "" XXX
|
||||||
|
SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX
|
||||||
|
SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 608 STEER_TORQUE_SENSOR: 8 XXX
|
||||||
|
SG_ STEER_TORQUE_EPS : 47|16@0- (0.73,0) [-20000|20000] "" XXX
|
||||||
|
SG_ STEER_TORQUE_DRIVER : 15|16@0- (1,0) [-32768|32767] "" XXX
|
||||||
|
SG_ STEER_OVERRIDE : 0|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 610 EPS_STATUS: 5 EPS
|
||||||
|
SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ LKA_STATE : 31|7@0+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ TYPE : 24|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 956 GEAR_PACKET: 8 XXX
|
||||||
|
SG_ SPORT_ON : 2|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ GEAR : 13|6@0+ (1,0) [0|63] "" XXX
|
||||||
|
SG_ ECON_ON : 40|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 705 GAS_PEDAL: 8 XXX
|
||||||
|
SG_ GAS_PEDAL : 55|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
|
||||||
|
CM_ SG_ 550 BRAKE_PRESSURE "seems prop to pedal force";
|
||||||
|
CM_ SG_ 550 BRAKE_POSITION "seems proportional to pedal displacement, unclear the max value of 0x1c8";
|
||||||
|
CM_ SG_ 610 TYPE "seems 1 on Corolla, 0 on all others";
|
||||||
|
VAL_ 610 IPAS_STATE 5 "override" 3 "enabled" 1 "disabled" ;
|
||||||
|
VAL_ 610 LKA_STATE 25 "temporary_fault" 9 "temporary_fault2" 5 "active" 1 "standby" ;
|
||||||
|
VAL_ 956 SPORT_ON 0 "off" 1 "on" ;
|
||||||
|
VAL_ 956 GEAR 0 "D" 1 "S" 8 "N" 16 "R" 32 "P" ;
|
||||||
|
VAL_ 956 ECON_ON 0 "off" 1 "on" ;
|
||||||
@@ -961,7 +961,7 @@ BO_ 64 DATC14: 8 DATC
|
|||||||
SG_ DATC_ADSDisp : 28|2@1+ (1.0,0.0) [0.0|3.0] "" CLU
|
SG_ DATC_ADSDisp : 28|2@1+ (1.0,0.0) [0.0|3.0] "" CLU
|
||||||
|
|
||||||
BO_ 832 LKAS11: 8 LDWS_LKAS
|
BO_ 832 LKAS11: 8 LDWS_LKAS
|
||||||
SG_ CF_Lkas_Icon : 0|2@1+ (1.0,0.0) [0.0|3.0] "" CLU,IBOX,PSB
|
SG_ CF_Lkas_Bca_R : 0|2@1+ (1.0,0.0) [0.0|3.0] "" CLU,IBOX,PSB
|
||||||
SG_ CF_Lkas_LdwsSysState : 2|4@1+ (1.0,0.0) [0.0|15.0] "" CLU,IBOX,PSB
|
SG_ CF_Lkas_LdwsSysState : 2|4@1+ (1.0,0.0) [0.0|15.0] "" CLU,IBOX,PSB
|
||||||
SG_ CF_Lkas_SysWarning : 6|4@1+ (1.0,0.0) [0.0|15.0] "" BCM,CLU
|
SG_ CF_Lkas_SysWarning : 6|4@1+ (1.0,0.0) [0.0|15.0] "" BCM,CLU
|
||||||
SG_ CF_Lkas_LdwsLHWarning : 10|2@1+ (1.0,0.0) [0.0|3.0] "" BCM,CLU,PSB
|
SG_ CF_Lkas_LdwsLHWarning : 10|2@1+ (1.0,0.0) [0.0|3.0] "" BCM,CLU,PSB
|
||||||
|
|||||||
@@ -0,0 +1,335 @@
|
|||||||
|
CM_ "AUTOGENERATED FILE, DO NOT EDIT"
|
||||||
|
|
||||||
|
|
||||||
|
CM_ "Imported file _comma.dbc starts here"
|
||||||
|
BO_ 359 STEERING_IPAS_COMMA: 8 IPAS
|
||||||
|
SG_ STATE : 7|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ ANGLE : 3|12@0- (1.5,0) [-510|510] "deg" XXX
|
||||||
|
SG_ SET_ME_X10 : 23|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_ME_X00 : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ DIRECTION_CMD : 38|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ SET_ME_X40 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_ME_X00 : 55|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
CM BO_ STEERING_IPAS_COMMA "Copy of msg 614 so we can do angle control while the Park Assist ECU is connected (Panda spoofs 614 with 359 on connector J70). Note that addresses 0x266 and 0x167 are checksum-invariant";
|
||||||
|
|
||||||
|
BO_ 512 GAS_COMMAND: 6 EON
|
||||||
|
SG_ GAS_COMMAND : 7|16@0+ (0.159375,-75.555) [0|1] "" INTERCEPTOR
|
||||||
|
SG_ GAS_COMMAND2 : 23|16@0+ (0.159375,-151.111) [0|1] "" INTERCEPTOR
|
||||||
|
SG_ ENABLE : 39|1@0+ (1,0) [0|1] "" INTERCEPTOR
|
||||||
|
SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" INTERCEPTOR
|
||||||
|
SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" INTERCEPTOR
|
||||||
|
|
||||||
|
BO_ 513 GAS_SENSOR: 6 INTERCEPTOR
|
||||||
|
SG_ INTERCEPTOR_GAS : 7|16@0+ (0.159375,-75.555) [0|1] "" EON
|
||||||
|
SG_ INTERCEPTOR_GAS2 : 23|16@0+ (0.159375,-151.111) [0|1] "" EON
|
||||||
|
SG_ STATE : 39|4@0+ (1,0) [0|15] "" EON
|
||||||
|
SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" EON
|
||||||
|
SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" EON
|
||||||
|
|
||||||
|
VAL_ 513 STATE 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
|
||||||
|
|
||||||
|
|
||||||
|
CM_ "Imported file _toyota_2017.dbc starts here"
|
||||||
|
VERSION ""
|
||||||
|
|
||||||
|
|
||||||
|
NS_ :
|
||||||
|
NS_DESC_
|
||||||
|
CM_
|
||||||
|
BA_DEF_
|
||||||
|
BA_
|
||||||
|
VAL_
|
||||||
|
CAT_DEF_
|
||||||
|
CAT_
|
||||||
|
FILTER
|
||||||
|
BA_DEF_DEF_
|
||||||
|
EV_DATA_
|
||||||
|
ENVVAR_DATA_
|
||||||
|
SGTYPE_
|
||||||
|
SGTYPE_VAL_
|
||||||
|
BA_DEF_SGTYPE_
|
||||||
|
BA_SGTYPE_
|
||||||
|
SIG_TYPE_REF_
|
||||||
|
VAL_TABLE_
|
||||||
|
SIG_GROUP_
|
||||||
|
SIG_VALTYPE_
|
||||||
|
SIGTYPE_VALTYPE_
|
||||||
|
BO_TX_BU_
|
||||||
|
BA_DEF_REL_
|
||||||
|
BA_REL_
|
||||||
|
BA_DEF_DEF_REL_
|
||||||
|
BU_SG_REL_
|
||||||
|
BU_EV_REL_
|
||||||
|
BU_BO_REL_
|
||||||
|
SG_MUL_VAL_
|
||||||
|
|
||||||
|
BS_:
|
||||||
|
|
||||||
|
BU_: XXX DSU HCU EPS IPAS
|
||||||
|
|
||||||
|
BO_ 36 KINEMATICS: 8 XXX
|
||||||
|
SG_ ACCEL_Y : 33|10@0+ (1,-512) [0|65535] "" XXX
|
||||||
|
SG_ YAW_RATE : 1|10@0+ (1,-512) [0|65535] "" XXX
|
||||||
|
SG_ STEERING_TORQUE : 17|10@0+ (1,-512) [0|65535] "" XXX
|
||||||
|
|
||||||
|
BO_ 37 STEER_ANGLE_SENSOR: 8 XXX
|
||||||
|
SG_ STEER_ANGLE : 3|12@0- (1.5,0) [-500|500] "deg" XXX
|
||||||
|
SG_ STEER_FRACTION : 39|4@0- (0.1,0) [-0.7|0.7] "deg" XXX
|
||||||
|
SG_ STEER_RATE : 35|12@0- (1,0) [-2000|2000] "deg/s" XXX
|
||||||
|
|
||||||
|
BO_ 166 BRAKE: 8 XXX
|
||||||
|
SG_ BRAKE_AMOUNT : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ BRAKE_PEDAL : 23|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 170 WHEEL_SPEEDS: 8 XXX
|
||||||
|
SG_ WHEEL_SPEED_FR : 7|16@0+ (0.01,-67.67) [0|250] "kph" XXX
|
||||||
|
SG_ WHEEL_SPEED_FL : 23|16@0+ (0.01,-67.67) [0|250] "kph" XXX
|
||||||
|
SG_ WHEEL_SPEED_RR : 39|16@0+ (0.01,-67.67) [0|250] "kph" XXX
|
||||||
|
SG_ WHEEL_SPEED_RL : 55|16@0+ (0.01,-67.67) [0|250] "kph" XXX
|
||||||
|
|
||||||
|
BO_ 180 SPEED: 8 XXX
|
||||||
|
SG_ ENCODER : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SPEED : 47|16@0+ (0.01,0) [0|250] "kph" XXX
|
||||||
|
|
||||||
|
BO_ 353 DSU_SPEED: 8 XXX
|
||||||
|
SG_ FORWARD_SPEED : 15|16@0- (0.00390625,-30) [0|255] "kph" XXX
|
||||||
|
|
||||||
|
BO_ 466 PCM_CRUISE: 8 XXX
|
||||||
|
SG_ GAS_RELEASED : 4|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CRUISE_ACTIVE : 5|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ STANDSTILL_ON : 12|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ACCEL_NET : 23|16@0- (0.001,0) [-20|20] "m/s2" XXX
|
||||||
|
SG_ CRUISE_STATE : 55|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 467 PCM_CRUISE_2: 8 XXX
|
||||||
|
SG_ MAIN_ON : 15|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LOW_SPEED_LOCKOUT : 14|2@0+ (1,0) [0|3] "kph" XXX
|
||||||
|
SG_ SET_SPEED : 23|8@0+ (1,0) [0|255] "kph" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 552 ACCELEROMETER: 8 XXX
|
||||||
|
SG_ ACCEL_Z : 22|15@0- (1,0) [0|32767] "" XXX
|
||||||
|
SG_ ACCEL_X : 6|15@0- (0.001,0) [-20|20] "m/s2" XXX
|
||||||
|
|
||||||
|
BO_ 560 BRAKE_MODULE2: 7 XXX
|
||||||
|
SG_ BRAKE_PRESSED : 26|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 614 STEERING_IPAS: 8 IPAS
|
||||||
|
SG_ STATE : 7|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ ANGLE : 3|12@0- (1.5,0) [-510|510] "deg" XXX
|
||||||
|
SG_ SET_ME_X10 : 23|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_ME_X00 : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ DIRECTION_CMD : 38|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ SET_ME_X40 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_ME_X00_1 : 55|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 643 PRE_COLLISION: 8 XXX
|
||||||
|
|
||||||
|
BO_ 740 STEERING_LKA: 5 XXX
|
||||||
|
SG_ LKA_STATE : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ STEER_REQUEST : 0|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ COUNTER : 6|6@0+ (1,0) [0|63] "" XXX
|
||||||
|
SG_ SET_ME_1 : 7|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ STEER_TORQUE_CMD : 15|16@0- (1,0) [0|65535] "" XXX
|
||||||
|
SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 742 LEAD_INFO: 8 DSU
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" HCU
|
||||||
|
SG_ LEAD_REL_SPEED : 23|12@0- (0.025,0) [-100|100] "m/s" HCU
|
||||||
|
SG_ LEAD_LONG_DIST : 7|13@0+ (0.05,0) [0|300] "m" HCU
|
||||||
|
|
||||||
|
BO_ 835 ACC_CONTROL: 8 DSU
|
||||||
|
SG_ ACCEL_CMD : 7|16@0- (0.001,0) [-20|20] "m/s2" HCU
|
||||||
|
SG_ SET_ME_X01 : 23|2@0+ (1,0) [0|3] "" HCU
|
||||||
|
SG_ DISTANCE : 20|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ MINI_CAR : 21|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X3 : 19|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ SET_ME_1 : 30|1@0+ (1,0) [0|1] "" HCU
|
||||||
|
SG_ RELEASE_STANDSTILL : 31|1@0+ (1,0) [0|1] "" HCU
|
||||||
|
SG_ CANCEL_REQ : 24|1@0+ (1,0) [0|1] "" HCU
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 921 PCM_CRUISE_SM: 8 XXX
|
||||||
|
SG_ MAIN_ON : 4|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CRUISE_CONTROL_STATE : 11|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ DISTANCE_LINES : 14|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ UI_SET_SPEED : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 951 ESP_CONTROL: 8 ESP
|
||||||
|
SG_ TC_DISABLED : 13|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ BRAKE_LIGHTS_ACC : 18|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1041 ACC_HUD: 8 DSU
|
||||||
|
SG_ FCW : 4|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X20 : 15|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X10 : 39|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X80 : 55|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1042 LKAS_HUD: 8 XXX
|
||||||
|
SG_ BARRIERS : 1|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ RIGHT_LINE : 3|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ LEFT_LINE : 5|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ SET_ME_X01 : 7|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ SET_ME_X01_2 : 11|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ LDA_ALERT : 9|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ TWO_BEEPS : 12|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ADJUSTING_CAMERA : 13|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LDA_MALFUNCTION : 15|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ REPEATED_BEEPS : 32|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X0C : 23|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X2C : 47|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X38 : 55|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SET_ME_X02 : 63|8@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1553 UI_SEETING: 8 XXX
|
||||||
|
SG_ UNITS : 26|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
|
||||||
|
BO_ 1556 STEERING_LEVERS: 8 XXX
|
||||||
|
SG_ TURN_SIGNALS : 29|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
|
||||||
|
BO_ 1568 SEATS_DOORS: 8 XXX
|
||||||
|
SG_ SEATBELT_DRIVER_UNLATCHED : 62|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_FL : 45|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_RL : 42|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_RR : 43|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_FR : 44|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1570 LIGHT_STALK: 8 SCM
|
||||||
|
SG_ AUTO_HIGH_BEAM : 37|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1161 RSA1: 8 FCM
|
||||||
|
SG_ TSGN1 : 7|8@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNGRY1 : 12|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNHLT1 : 9|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPDVAL1 : 23|8@0+ (1,0) [0|0] "kph" XXX
|
||||||
|
SG_ SPLSGN1 : 31|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPLSGN2 : 27|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGN2 : 39|8@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNGRY2 : 44|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNHLT2 : 41|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPDVAL2 : 55|8@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ BZRRQ_P : 63|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ BZRRQ_A : 61|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SYNCID1 : 59|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
|
||||||
|
BO_ 1162 RSA2: 8 FCM
|
||||||
|
SG_ TSGN3 : 7|8@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNGRY3 : 12|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNHLT3 : 9|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPLSGN3 : 31|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPLSGN4 : 27|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGN4 : 39|8@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNGRY4 : 44|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSGNHLT4 : 41|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ DPSGNREQ : 54|1@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SGNNUMP : 53|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SGNNUMA : 50|3@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SPDUNT : 63|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSRWMSG : 61|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ SYNCID2 : 59|4@0+ (1,0) [0|0] "" XXX
|
||||||
|
|
||||||
|
BO_ 1163 RSA3: 8 FCM
|
||||||
|
SG_ TSREQPD : 7|1@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ TSRMSW : 6|1@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ OTSGNNTM : 5|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ NTLVLSPD : 3|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ OVSPNTM : 1|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ OVSPVALL : 11|4@0+ (1,-5) [0|0] "" XXX
|
||||||
|
SG_ OVSPVALM : 19|4@0+ (1,-5) [0|0] "" XXX
|
||||||
|
SG_ OVSPVALH : 27|4@0+ (1,-5) [0|0] "" XXX
|
||||||
|
SG_ TSRSPU : 33|2@0+ (1,0) [0|0] "" XXX
|
||||||
|
|
||||||
|
CM_ SG_ 36 ACCEL_Y "unit is tbd";
|
||||||
|
CM_ SG_ 36 YAW_RATE "verify";
|
||||||
|
CM_ SG_ 36 STEERING_TORQUE "does not seem the steer torque, tbd";
|
||||||
|
CM_ SG_ 37 STEER_FRACTION "1/15th of the signal STEER_ANGLE, which is 1.5 deg; note that 0x8 is never set";
|
||||||
|
CM_ SG_ 37 STEER_RATE "factor is tbd";
|
||||||
|
CM_ SG_ 466 ACCEL_NET "net acceleration produced by the system, given ACCEL_CMD, road grade and other factors";
|
||||||
|
CM_ SG_ 467 SET_SPEED "43 kph are shown as 28mph, so conversion isnt perfect";
|
||||||
|
CM_ SG_ 467 LOW_SPEED_LOCKOUT "in low speed lockout, system would always disengage below 28mph";
|
||||||
|
CM_ SG_ 560 BRAKE_PRESSED "another brake pressed?";
|
||||||
|
CM_ SG_ 608 STEER_TORQUE_DRIVER "driver torque";
|
||||||
|
CM_ SG_ 608 STEER_OVERRIDE "set when driver torque exceeds a certain value";
|
||||||
|
CM_ SG_ 614 ANGLE "set to measured angle when ipas control isn't active";
|
||||||
|
CM_ SG_ 921 UI_SET_SPEED "set speed shown in UI with user set unit";
|
||||||
|
CM_ SG_ 951 BRAKE_LIGHTS_ACC "brake lights when ACC commands decel";
|
||||||
|
CM_ SG_ 1042 SET_ME_1 "unclear what this is, but it's always 1 in drive traces";
|
||||||
|
CM_ SG_ 1042 REPEATED_BEEPS "recommended for fcw and other important alerts";
|
||||||
|
CM_ SG_ 1161 SPDVAL1 "Numbers 0-199 is displayed, 200-254 displays circle without number and 255 is for no limit.";
|
||||||
|
CM_ SG_ 1161 SYNCID1 "counter from 1 to f at 1 Hz";
|
||||||
|
CM_ SG_ 1161 SPDVAL2 "conditional speed value 70"
|
||||||
|
CM_ SG_ 1162 SGNNUMP "1 if SPDVAL1 is set, otherwise 0";
|
||||||
|
CM_ SG_ 1162 SYNCID2 "counter from 1 to f at 1 Hz";
|
||||||
|
CM_ SG_ 1163 TSREQPD "always 1";
|
||||||
|
CM_ SG_ 1163 TSRMSW "always 1";
|
||||||
|
CM_ SG_ 1163 OTSGNNTM "always 3";
|
||||||
|
CM_ SG_ 1163 NTLVLSPD "always 3";
|
||||||
|
CM_ SG_ 1163 OVSPNTM "always 3";
|
||||||
|
CM_ SG_ 1163 OVSPVALL "-5 at start then 2 after 2 seconds";
|
||||||
|
CM_ SG_ 1163 OVSPVALM "-5 at start then 5 after 2 seconds";
|
||||||
|
CM_ SG_ 1163 OVSPVALH "-5 at start then 10 after 2 seconds";
|
||||||
|
CM_ SG_ 1163 TSRSPU "always 1";
|
||||||
|
|
||||||
|
VAL_ 466 CRUISE_STATE 8 "active" 7 "standstill" 1 "off";
|
||||||
|
VAL_ 467 LOW_SPEED_LOCKOUT 2 "low speed locked" 1 "ok";
|
||||||
|
VAL_ 614 STATE 3 "enabled" 1 "disabled";
|
||||||
|
VAL_ 614 DIRECTION_CMD 3 "right" 2 "center" 1 "left";
|
||||||
|
VAL_ 921 CRUISE_CONTROL_STATE 2 "disabled" 11 "hold" 10 "hold_waiting_user_cmd" 6 "enabled" 5 "faulted";
|
||||||
|
VAL_ 1042 LDA_ALERT 3 "hold with continuous beep" 2 "LDA unavailable" 1 "hold" 0 "none";
|
||||||
|
VAL_ 1042 BARRIERS 3 "both" 2 "right" 1 "left" 0 "none";
|
||||||
|
VAL_ 1042 RIGHT_LINE 3 "orange" 2 "faded" 1 "solid" 0 "none";
|
||||||
|
VAL_ 1042 LEFT_LINE 3 "orange" 2 "faded" 1 "solid" 0 "none";
|
||||||
|
VAL_ 1553 UNITS 1 "km" 2 "miles";
|
||||||
|
VAL_ 1556 TURN_SIGNALS 3 "none" 2 "right" 1 "left";
|
||||||
|
VAL_ 1161 TSGN1 1 "speed sign" 0 "none";
|
||||||
|
VAL_ 1161 TSGN2 1 "speed sign" 0 "none";
|
||||||
|
VAL_ 1161 SPLSGN2 15 "conditional blank" 4 "wet road" 5 "rain" 0 "none";
|
||||||
|
VAL_ 1162 TSGN3 0 "none" 1 "speed sign" 2 "0 unlimited" 7 "unlimited" 16 "highway" 17 "no highway" 18 "motorway" 19 "no motorway" 20 "in city" 21 "outside city" 22 "pedestrian area" 23 "no pedestrian area" 65 "no overtaking left" 66 "no overtaking right" 67 "overtaking allowed again" 129 "no entry";
|
||||||
|
VAL_ 1162 SPLSGN3 15 "conditional blank" 4 "wet road" 5 "rain" 0 "none";
|
||||||
|
|
||||||
|
|
||||||
|
CM_ "CHFFR_METRIC 37 STEER_ANGLE STEER_ANGLE 0.36 180";
|
||||||
|
|
||||||
|
CM_ "lexus_rx_350_2016_pt.dbc starts here"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BO_ 550 BRAKE_MODULE: 8 XXX
|
||||||
|
SG_ BRAKE_PRESSURE : 0|9@0+ (1,0) [0|511] "" XXX
|
||||||
|
SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX
|
||||||
|
SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 608 STEER_TORQUE_SENSOR: 8 XXX
|
||||||
|
SG_ STEER_TORQUE_EPS : 47|16@0- (0.73,0) [-20000|20000] "" XXX
|
||||||
|
SG_ STEER_TORQUE_DRIVER : 15|16@0- (1,0) [-32768|32767] "" XXX
|
||||||
|
SG_ STEER_OVERRIDE : 0|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 610 EPS_STATUS: 5 EPS
|
||||||
|
SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ LKA_STATE : 31|7@0+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ TYPE : 24|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 956 GEAR_PACKET: 8 XXX
|
||||||
|
SG_ SPORT_ON : 2|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ GEAR : 13|6@0+ (1,0) [0|63] "" XXX
|
||||||
|
SG_ ECON_ON : 40|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 705 GAS_PEDAL: 8 XXX
|
||||||
|
SG_ GAS_PEDAL : 55|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
|
||||||
|
CM_ SG_ 550 BRAKE_PRESSURE "seems prop to pedal force";
|
||||||
|
CM_ SG_ 550 BRAKE_POSITION "seems proportional to pedal displacement, unclear the max value of 0x1c8";
|
||||||
|
CM_ SG_ 610 TYPE "seems 1 on Corolla, 0 on all others";
|
||||||
|
VAL_ 610 IPAS_STATE 5 "override" 3 "enabled" 1 "disabled" ;
|
||||||
|
VAL_ 610 LKA_STATE 25 "temporary_fault" 9 "temporary_fault2" 5 "active" 1 "standby" ;
|
||||||
|
VAL_ 956 SPORT_ON 0 "off" 1 "on" ;
|
||||||
|
VAL_ 956 GEAR 0 "D" 1 "S" 8 "N" 16 "R" 32 "P" ;
|
||||||
|
VAL_ 956 ECON_ON 0 "off" 1 "on" ;
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
VERSION ""
|
||||||
|
|
||||||
|
|
||||||
|
NS_ :
|
||||||
|
NS_DESC_
|
||||||
|
CM_
|
||||||
|
BA_DEF_
|
||||||
|
BA_
|
||||||
|
VAL_
|
||||||
|
CAT_DEF_
|
||||||
|
CAT_
|
||||||
|
FILTER
|
||||||
|
BA_DEF_DEF_
|
||||||
|
EV_DATA_
|
||||||
|
ENVVAR_DATA_
|
||||||
|
SGTYPE_
|
||||||
|
SGTYPE_VAL_
|
||||||
|
BA_DEF_SGTYPE_
|
||||||
|
BA_SGTYPE_
|
||||||
|
SIG_TYPE_REF_
|
||||||
|
VAL_TABLE_
|
||||||
|
SIG_GROUP_
|
||||||
|
SIG_VALTYPE_
|
||||||
|
SIGTYPE_VALTYPE_
|
||||||
|
BO_TX_BU_
|
||||||
|
BA_DEF_REL_
|
||||||
|
BA_REL_
|
||||||
|
BA_DEF_DEF_REL_
|
||||||
|
BU_SG_REL_
|
||||||
|
BU_EV_REL_
|
||||||
|
BU_BO_REL_
|
||||||
|
SG_MUL_VAL_
|
||||||
|
|
||||||
|
BS_:
|
||||||
|
|
||||||
|
BU_: XXX
|
||||||
|
|
||||||
|
|
||||||
|
BO_ 644 Speed_1: 8 XXX
|
||||||
|
SG_ Speed_FR : 7|16@0+ (0.0118,0) [0|65535] "" XXX
|
||||||
|
SG_ Speed_FL : 23|16@0+ (0.0118,0) [0|65535] "" XXX
|
||||||
|
SG_ Speed_Vehicle : 39|16@0+ (0.0245,0) [0|65535] "" XXX
|
||||||
|
|
||||||
|
BO_ 645 WheelspeedRear: 8 XXX
|
||||||
|
SG_ RR : 7|16@0+ (0.00555,0) [0|65535] "KPH" XXX
|
||||||
|
SG_ RL : 23|16@0+ (0.00555,0) [0|65535] "KPH" XXX
|
||||||
|
|
||||||
|
BO_ 768 STEER_TORQUE: 8 XXX
|
||||||
|
SG_ STEERING_TOURQUE : 0|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
|
||||||
|
BO_ 459 Maybe_RegenBraking: 8 XXX
|
||||||
|
|
||||||
|
BO_ 372 Maybe_Gear_Selector: 8 XXX
|
||||||
|
SG_ Counter : 32|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
|
||||||
|
BO_ 374 Maybe_Motor_RPM_or_Speed: 8 XXX
|
||||||
|
SG_ Counter : 48|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
|
||||||
|
BO_ 460 Maybe_Brake_Related: 8 XXX
|
||||||
|
|
||||||
|
BO_ 2 SteeringWheel: 8 XXX
|
||||||
|
SG_ Steering_RateChange : 23|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ Always_07 : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ Steering_Angle : 0|16@1- (-0.1,0) [0|65535] "" XXX
|
||||||
|
|
||||||
|
BO_ 384 Maybe_PowerInfo: 8 XXX
|
||||||
|
SG_ Unknown_Timer_PowerInfo : 48|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ EnginePower : 27|12@0- (1,0) [0|1] "" XXX
|
||||||
|
SG_ RequestedAccel : 23|12@0- (1,0) [0|4294967295] "" XXX
|
||||||
|
|
||||||
|
BO_ 1107 Lights: 8 XXX
|
||||||
|
SG_ RIGHT_BLINKER : 12|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LEFT_BLINKER : 11|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ _HEADLIGHTS : 5|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 666 WheelspeedFront: 8 XXX
|
||||||
|
SG_ _FL_WHEELSPEED : 39|16@0+ (0.01014,0) [0|65535] "" XXX
|
||||||
|
SG_ FR : 7|16@0+ (0.00555,0) [0|65535] "KPH" XXX
|
||||||
|
SG_ FL : 23|16@0+ (0.00555,0) [0|65535] "KPH" XXX
|
||||||
|
|
||||||
|
BO_ 398 NEW_MSG_2: 8 XXX
|
||||||
|
|
||||||
|
BO_ 389 NEW_MSG_3: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 15|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_2 : 22|6@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_4 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_5 : 55|4@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_6 : 63|8@0+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ COUNTER : 48|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_3 : 30|8@0- (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 397 NEW_MSG_4: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_2 : 23|16@0+ (1,0) [0|32767] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_3 : 39|16@0+ (1,0) [0|65535] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_4 : 55|16@0+ (1,0) [0|31] "" XXX
|
||||||
|
|
||||||
|
BO_ 658 NEW_MSG_5: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 855 NEW_MSG_6: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 773 NEW_MSG_7: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_2 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 851 SPEED_RELATED: 8 XXX
|
||||||
|
SG_ SPEED_RELATED : 7|16@0+ (0.01014,0) [0|65535] "" XXX
|
||||||
|
|
||||||
|
BO_ 386 Accelerator: 8 XXX
|
||||||
|
SG_ Accelerator : 38|7@0+ (1,0) [0|127] "" XXX
|
||||||
|
|
||||||
|
BO_ 347 ACCELSOMETHING: 8 XXX
|
||||||
|
SG_ PowerMaybe : 9|10@0+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ ACCELERATOR2 : 6|11@0+ (1,-800) [0|65535] "" XXX
|
||||||
|
|
||||||
|
BO_ 346 ANOTHER_ACCEL: 8 XXX
|
||||||
|
SG_ ANOTHERACCEL : 23|10@0+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ Reverse_ACCEL : 25|10@0+ (1,0) [0|1023] "" XXX
|
||||||
|
|
||||||
|
BO_ 348 FULLRANGEACCEL: 8 XXX
|
||||||
|
SG_ AccelFullRange : 47|10@0+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ Accel : 26|11@0+ (1,0) [0|2047] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 566 ANOTHERFULLRANGEACCEL: 8 XXX
|
||||||
|
SG_ ANOTHERFULLRANGEACCEL : 43|8@0+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ RPMORTORQUE : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 523 Yetyetanotheraccel: 8 XXX
|
||||||
|
SG_ ANOTHERREVERSEACCEL : 37|10@0+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ yetyetanotheraccel : 31|10@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 779 ANOTHERRRFULLRANGEACCEL: 8 XXX
|
||||||
|
SG_ ANOTHERRRFULLRANGEACCEL : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 1108 Doors: 8 XXX
|
||||||
|
SG_ DOOR_CLOSED_RR : 40|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_RR : 41|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_CLOSED_RL : 42|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_RL : 43|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_CLOSED_FL : 44|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_OPEN_FL : 45|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ DOOR_CLOSED_FR : 46|1@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ DOOR_OPEN_FR : 47|1@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ BOOT_OPEN : 55|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 403 LKAS_OLD: 8 XXX
|
||||||
|
SG_ Checksum : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ Angle_2 : 32|13@0+ (1,-4000) [0|63] "" XXX
|
||||||
|
SG_ Counter : 48|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ Angle_1 : 10|13@0+ (0.12,-480) [0|65535] "" XXX
|
||||||
|
SG_ Steering_Torque : 7|13@0+ (-1,4000) [0|65535] "" XXX
|
||||||
|
SG_ Torque_Command : 29|13@0+ (1,-4000) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 412 NEW_MSG_9: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|65535] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_3 : 23|16@0+ (1,0) [0|65535] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_2 : 39|8@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_4 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 361 LKAS: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_4 : 39|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_X80 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ LKA_Active : 52|1@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ CRC : 63|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_0x80_2 : 31|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ Counter : 51|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ Des_Angle : 7|18@0+ (-0.01,1310) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 438 ProPilot: 8 XXX
|
||||||
|
SG_ NEW_SIGNAL_2 : 11|4@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_4 : 27|4@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_8 : 63|8@0+ (1,0) [0|7] "" XXX
|
||||||
|
SG_ Counter : 55|4@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_6 : 47|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ SET_3 : 32|2@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_1 : 7|12@0- (1,0) [0|255] "" XXX
|
||||||
|
SG_ NEW_SIGNAL_3 : 23|12@0- (-1,0) [0|255] "" XXX
|
||||||
|
SG_ CRUISE_ON : 36|1@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ CRUISE_ACTIVATED : 38|1@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ STEER_STATUS : 51|1@1+ (1,0) [0|3] "" XXX
|
||||||
|
|
||||||
+14
-21
@@ -32,26 +32,6 @@ jobs:
|
|||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
name: Store misra test output
|
name: Store misra test output
|
||||||
path: /tmp/misra/misra_output.txt
|
path: /tmp/misra/misra_output.txt
|
||||||
- store_artifacts:
|
|
||||||
name: Store cppcheck safety test output
|
|
||||||
path: /tmp/misra/cppcheck_safety_output.txt
|
|
||||||
- store_artifacts:
|
|
||||||
name: Store misra safety test output
|
|
||||||
path: /tmp/misra/misra_safety_output.txt
|
|
||||||
|
|
||||||
|
|
||||||
strict-compiler:
|
|
||||||
machine:
|
|
||||||
docker_layer_caching: true
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- run:
|
|
||||||
name: Build image
|
|
||||||
command: "docker build -t panda_strict_compiler -f tests/build_strict/Dockerfile ."
|
|
||||||
- run:
|
|
||||||
name: Build Panda with strict compiler rules
|
|
||||||
command: |
|
|
||||||
docker run panda_strict_compiler /bin/bash -c "cd /panda/tests/build_strict; ./test_build_strict.sh"
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
machine:
|
machine:
|
||||||
@@ -99,12 +79,25 @@ jobs:
|
|||||||
command: |
|
command: |
|
||||||
docker run panda_safety_replay /bin/bash -c "cd /openpilot/panda/tests/safety_replay; PYTHONPATH=/openpilot ./test_safety_replay.py"
|
docker run panda_safety_replay /bin/bash -c "cd /openpilot/panda/tests/safety_replay; PYTHONPATH=/openpilot ./test_safety_replay.py"
|
||||||
|
|
||||||
|
language_check:
|
||||||
|
machine:
|
||||||
|
docker_layer_caching: true
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: Build image
|
||||||
|
command: "docker build -t language_check -f tests/language/Dockerfile ."
|
||||||
|
- run:
|
||||||
|
name: Check code for bad language
|
||||||
|
command: |
|
||||||
|
docker run language_check /bin/bash -c "cd /panda/tests/language; ./test_language.py"
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
main:
|
main:
|
||||||
jobs:
|
jobs:
|
||||||
- safety
|
- safety
|
||||||
- misra-c2012
|
- misra-c2012
|
||||||
- strict-compiler
|
|
||||||
- build
|
- build
|
||||||
- safety_replay
|
- safety_replay
|
||||||
|
- language_check
|
||||||
|
|||||||
Vendored
+30
-10
@@ -20,33 +20,53 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Test Dev Build') {
|
stage('Test Dev Build (no WIFI)') {
|
||||||
steps {
|
steps {
|
||||||
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
|
lock(resource: "Pandas", inversePrecedence: true, quantity: 1){
|
||||||
timeout(time: 60, unit: 'MINUTES') {
|
timeout(time: 60, unit: 'MINUTES') {
|
||||||
sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; ./run_automated_tests.sh '"
|
script {
|
||||||
|
sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; SKIPWIFI=1 ./run_automated_tests.sh'"
|
||||||
|
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev_nowifi.xml"
|
||||||
|
sh "docker rm ${env.DOCKER_NAME}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Test EON Build') {
|
stage('Test EON Build') {
|
||||||
steps {
|
steps {
|
||||||
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
|
lock(resource: "Pandas", inversePrecedence: true, quantity: 1){
|
||||||
timeout(time: 60, unit: 'MINUTES') {
|
timeout(time: 60, unit: 'MINUTES') {
|
||||||
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml"
|
script {
|
||||||
sh "touch EON && docker cp EON ${env.DOCKER_NAME}:/EON"
|
sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'touch /EON; cd /tmp/panda; ./run_automated_tests.sh'"
|
||||||
sh "docker start -a ${env.DOCKER_NAME}"
|
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_eon.xml"
|
||||||
|
sh "docker rm ${env.DOCKER_NAME}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Test Dev Build (WIFI)') {
|
||||||
|
steps {
|
||||||
|
lock(resource: "Pandas", inversePrecedence: true, quantity: 1){
|
||||||
|
timeout(time: 60, unit: 'MINUTES') {
|
||||||
|
script {
|
||||||
|
sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; ./run_automated_tests.sh'"
|
||||||
|
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml"
|
||||||
|
sh "docker rm ${env.DOCKER_NAME}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
failure {
|
||||||
script {
|
script {
|
||||||
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_EON.xml"
|
sh "docker rm ${env.DOCKER_NAME} || true"
|
||||||
sh "docker rm ${env.DOCKER_NAME}"
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
always {
|
||||||
junit "test_results*.xml"
|
junit "test_results*.xml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
v1.4.0
|
v1.4.2
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
PROJ_NAME = panda
|
PROJ_NAME = panda
|
||||||
CFLAGS = -g -Wall
|
CFLAGS = -g -Wall -Wextra -Wstrict-prototypes -Werror
|
||||||
|
|
||||||
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
||||||
CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant
|
CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
PROJ_NAME = panda
|
|
||||||
CFLAGS = -g -Wall -Wextra -Wstrict-prototypes
|
|
||||||
|
|
||||||
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
|
||||||
CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant
|
|
||||||
STARTUP_FILE = startup_stm32f413xx
|
|
||||||
|
|
||||||
include build.mk
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// ///////////////////////////////////////////////////////////// //
|
||||||
|
// Hardware abstraction layer for all different supported boards //
|
||||||
|
// ///////////////////////////////////////////////////////////// //
|
||||||
|
#include "board_declarations.h"
|
||||||
|
#include "boards/common.h"
|
||||||
|
|
||||||
|
// ///// Board definition and detection ///// //
|
||||||
|
#include "drivers/harness.h"
|
||||||
|
#ifdef PANDA
|
||||||
|
#include "boards/white.h"
|
||||||
|
#include "boards/grey.h"
|
||||||
|
#include "boards/black.h"
|
||||||
|
#else
|
||||||
|
#include "boards/pedal.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void detect_board_type(void) {
|
||||||
|
#ifdef PANDA
|
||||||
|
// SPI lines floating: white (TODO: is this reliable?)
|
||||||
|
if((detect_with_pull(GPIOA, 4, PULL_DOWN)) || (detect_with_pull(GPIOA, 5, PULL_DOWN)) || (detect_with_pull(GPIOA, 6, PULL_DOWN)) || (detect_with_pull(GPIOA, 7, PULL_DOWN))){
|
||||||
|
hw_type = HW_TYPE_WHITE_PANDA;
|
||||||
|
current_board = &board_white;
|
||||||
|
} else if(detect_with_pull(GPIOA, 13, PULL_DOWN)) { // Rev AB deprecated, so no pullup means black. In REV C, A13 is pulled up to 5V with a 10K
|
||||||
|
hw_type = HW_TYPE_GREY_PANDA;
|
||||||
|
current_board = &board_grey;
|
||||||
|
} else {
|
||||||
|
hw_type = HW_TYPE_BLACK_PANDA;
|
||||||
|
current_board = &board_black;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#ifdef PEDAL
|
||||||
|
hw_type = HW_TYPE_PEDAL;
|
||||||
|
current_board = &board_pedal;
|
||||||
|
#else
|
||||||
|
hw_type = HW_TYPE_UNKNOWN;
|
||||||
|
puts("Hardware type is UNKNOWN!\n");
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ///// Configuration detection ///// //
|
||||||
|
bool has_external_debug_serial = 0;
|
||||||
|
bool is_entering_bootmode = 0;
|
||||||
|
|
||||||
|
void detect_configuration(void) {
|
||||||
|
// detect if external serial debugging is present
|
||||||
|
has_external_debug_serial = detect_with_pull(GPIOA, 3, PULL_DOWN);
|
||||||
|
|
||||||
|
#ifdef PANDA
|
||||||
|
// check if the ESP is trying to put me in boot mode
|
||||||
|
is_entering_bootmode = !detect_with_pull(GPIOB, 0, PULL_UP);
|
||||||
|
#else
|
||||||
|
is_entering_bootmode = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// ///// Board functions ///// //
|
||||||
|
bool board_has_gps(void) {
|
||||||
|
return ((hw_type == HW_TYPE_GREY_PANDA) || (hw_type == HW_TYPE_BLACK_PANDA));
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// ******************** Prototypes ********************
|
||||||
|
typedef void (*board_init)(void);
|
||||||
|
typedef void (*board_enable_can_transciever)(uint8_t transciever, bool enabled);
|
||||||
|
typedef void (*board_enable_can_transcievers)(bool enabled);
|
||||||
|
typedef void (*board_set_led)(uint8_t color, bool enabled);
|
||||||
|
typedef void (*board_set_usb_power_mode)(uint8_t mode);
|
||||||
|
typedef void (*board_set_esp_gps_mode)(uint8_t mode);
|
||||||
|
typedef void (*board_set_can_mode)(uint8_t mode);
|
||||||
|
typedef void (*board_usb_power_mode_tick)(uint64_t tcnt);
|
||||||
|
typedef bool (*board_check_ignition)(void);
|
||||||
|
|
||||||
|
struct board {
|
||||||
|
const char *board_type;
|
||||||
|
const harness_configuration *harness_config;
|
||||||
|
board_init init;
|
||||||
|
board_enable_can_transciever enable_can_transciever;
|
||||||
|
board_enable_can_transcievers enable_can_transcievers;
|
||||||
|
board_set_led set_led;
|
||||||
|
board_set_usb_power_mode set_usb_power_mode;
|
||||||
|
board_set_esp_gps_mode set_esp_gps_mode;
|
||||||
|
board_set_can_mode set_can_mode;
|
||||||
|
board_usb_power_mode_tick usb_power_mode_tick;
|
||||||
|
board_check_ignition check_ignition;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ******************* Definitions ********************
|
||||||
|
// These should match the enum in cereal/log.capnp
|
||||||
|
#define HW_TYPE_UNKNOWN 0U
|
||||||
|
#define HW_TYPE_WHITE_PANDA 1U
|
||||||
|
#define HW_TYPE_GREY_PANDA 2U
|
||||||
|
#define HW_TYPE_BLACK_PANDA 3U
|
||||||
|
#define HW_TYPE_PEDAL 4U
|
||||||
|
|
||||||
|
// LED colors
|
||||||
|
#define LED_RED 0U
|
||||||
|
#define LED_GREEN 1U
|
||||||
|
#define LED_BLUE 2U
|
||||||
|
|
||||||
|
// USB power modes
|
||||||
|
#define USB_POWER_NONE 0U
|
||||||
|
#define USB_POWER_CLIENT 1U
|
||||||
|
#define USB_POWER_CDP 2U
|
||||||
|
#define USB_POWER_DCP 3U
|
||||||
|
|
||||||
|
// ESP modes
|
||||||
|
#define ESP_GPS_DISABLED 0U
|
||||||
|
#define ESP_GPS_ENABLED 1U
|
||||||
|
#define ESP_GPS_BOOTMODE 2U
|
||||||
|
|
||||||
|
// CAN modes
|
||||||
|
#define CAN_MODE_NORMAL 0U
|
||||||
|
#define CAN_MODE_GMLAN_CAN2 1U
|
||||||
|
#define CAN_MODE_GMLAN_CAN3 2U
|
||||||
|
#define CAN_MODE_OBD_CAN2 3U
|
||||||
|
|
||||||
|
// ********************* Globals **********************
|
||||||
|
uint8_t usb_power_mode = USB_POWER_NONE;
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
// ///////////////////// //
|
||||||
|
// Black Panda + Harness //
|
||||||
|
// ///////////////////// //
|
||||||
|
|
||||||
|
void black_enable_can_transciever(uint8_t transciever, bool enabled) {
|
||||||
|
switch (transciever){
|
||||||
|
case 1U:
|
||||||
|
set_gpio_output(GPIOC, 1, !enabled);
|
||||||
|
break;
|
||||||
|
case 2U:
|
||||||
|
set_gpio_output(GPIOC, 13, !enabled);
|
||||||
|
break;
|
||||||
|
case 3U:
|
||||||
|
set_gpio_output(GPIOA, 0, !enabled);
|
||||||
|
break;
|
||||||
|
case 4U:
|
||||||
|
set_gpio_output(GPIOB, 10, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Invalid CAN transciever ("); puth(transciever); puts("): enabling failed\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_enable_can_transcievers(bool enabled) {
|
||||||
|
for(uint8_t i=1; i<=4U; i++)
|
||||||
|
black_enable_can_transciever(i, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_set_led(uint8_t color, bool enabled) {
|
||||||
|
switch (color){
|
||||||
|
case LED_RED:
|
||||||
|
set_gpio_output(GPIOC, 9, !enabled);
|
||||||
|
break;
|
||||||
|
case LED_GREEN:
|
||||||
|
set_gpio_output(GPIOC, 7, !enabled);
|
||||||
|
break;
|
||||||
|
case LED_BLUE:
|
||||||
|
set_gpio_output(GPIOC, 6, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_set_usb_power_mode(uint8_t mode){
|
||||||
|
usb_power_mode = mode;
|
||||||
|
puts("Trying to set USB power mode on black panda. This is not supported.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_set_esp_gps_mode(uint8_t mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case ESP_GPS_DISABLED:
|
||||||
|
// ESP OFF
|
||||||
|
set_gpio_output(GPIOC, 14, 0);
|
||||||
|
set_gpio_output(GPIOC, 5, 0);
|
||||||
|
break;
|
||||||
|
case ESP_GPS_ENABLED:
|
||||||
|
// ESP ON
|
||||||
|
set_gpio_output(GPIOC, 14, 1);
|
||||||
|
set_gpio_output(GPIOC, 5, 1);
|
||||||
|
break;
|
||||||
|
case ESP_GPS_BOOTMODE:
|
||||||
|
set_gpio_output(GPIOC, 14, 1);
|
||||||
|
set_gpio_output(GPIOC, 5, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Invalid ESP/GPS mode\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_set_can_mode(uint8_t mode){
|
||||||
|
switch (mode) {
|
||||||
|
case CAN_MODE_NORMAL:
|
||||||
|
case CAN_MODE_OBD_CAN2:
|
||||||
|
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) {
|
||||||
|
// B12,B13: disable OBD mode
|
||||||
|
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
||||||
|
|
||||||
|
// B5,B6: normal CAN2 mode
|
||||||
|
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
||||||
|
} else {
|
||||||
|
// B5,B6: disable normal CAN2 mode
|
||||||
|
set_gpio_mode(GPIOB, 5, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 6, MODE_INPUT);
|
||||||
|
|
||||||
|
// B12,B13: OBD mode
|
||||||
|
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_usb_power_mode_tick(uint64_t tcnt){
|
||||||
|
UNUSED(tcnt);
|
||||||
|
// Not applicable
|
||||||
|
}
|
||||||
|
|
||||||
|
bool black_check_ignition(void){
|
||||||
|
// ignition is checked through harness
|
||||||
|
return harness_check_ignition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void black_init(void) {
|
||||||
|
common_init_gpio();
|
||||||
|
|
||||||
|
// A8,A15: normal CAN3 mode
|
||||||
|
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||||
|
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||||
|
|
||||||
|
// C0: OBD_SBU1 (orientation detection)
|
||||||
|
// C3: OBD_SBU2 (orientation detection)
|
||||||
|
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
||||||
|
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
||||||
|
|
||||||
|
// C10: OBD_SBU1_RELAY (harness relay driving output)
|
||||||
|
// C11: OBD_SBU2_RELAY (harness relay driving output)
|
||||||
|
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
|
||||||
|
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
|
||||||
|
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
|
||||||
|
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
|
||||||
|
set_gpio_output(GPIOC, 10, 1);
|
||||||
|
set_gpio_output(GPIOC, 11, 1);
|
||||||
|
|
||||||
|
// C8: FAN aka TIM3_CH3
|
||||||
|
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
||||||
|
|
||||||
|
// C12: GPS load switch. Turn on permanently for now
|
||||||
|
set_gpio_output(GPIOC, 12, true);
|
||||||
|
//set_gpio_output(GPIOC, 12, false); //TODO: stupid inverted switch on prototype
|
||||||
|
|
||||||
|
// Initialize harness
|
||||||
|
harness_init();
|
||||||
|
|
||||||
|
// Enable CAN transcievers
|
||||||
|
black_enable_can_transcievers(true);
|
||||||
|
|
||||||
|
// Disable LEDs
|
||||||
|
black_set_led(LED_RED, false);
|
||||||
|
black_set_led(LED_GREEN, false);
|
||||||
|
black_set_led(LED_BLUE, false);
|
||||||
|
|
||||||
|
// Set normal CAN mode
|
||||||
|
black_set_can_mode(CAN_MODE_NORMAL);
|
||||||
|
|
||||||
|
// flip CAN0 and CAN2 if we are flipped
|
||||||
|
if (car_harness_status == HARNESS_STATUS_NORMAL) {
|
||||||
|
can_flip_buses(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init multiplexer
|
||||||
|
can_set_obd(car_harness_status, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const harness_configuration black_harness_config = {
|
||||||
|
.has_harness = true,
|
||||||
|
.GPIO_SBU1 = GPIOC,
|
||||||
|
.GPIO_SBU2 = GPIOC,
|
||||||
|
.GPIO_relay_normal = GPIOC,
|
||||||
|
.GPIO_relay_flipped = GPIOC,
|
||||||
|
.pin_SBU1 = 0,
|
||||||
|
.pin_SBU2 = 3,
|
||||||
|
.pin_relay_normal = 10,
|
||||||
|
.pin_relay_flipped = 11,
|
||||||
|
.adc_channel_SBU1 = 10,
|
||||||
|
.adc_channel_SBU2 = 13
|
||||||
|
};
|
||||||
|
|
||||||
|
const board board_black = {
|
||||||
|
.board_type = "Black",
|
||||||
|
.harness_config = &black_harness_config,
|
||||||
|
.init = black_init,
|
||||||
|
.enable_can_transciever = black_enable_can_transciever,
|
||||||
|
.enable_can_transcievers = black_enable_can_transcievers,
|
||||||
|
.set_led = black_set_led,
|
||||||
|
.set_usb_power_mode = black_set_usb_power_mode,
|
||||||
|
.set_esp_gps_mode = black_set_esp_gps_mode,
|
||||||
|
.set_can_mode = black_set_can_mode,
|
||||||
|
.usb_power_mode_tick = black_usb_power_mode_tick,
|
||||||
|
.check_ignition = black_check_ignition
|
||||||
|
};
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#ifdef STM32F4
|
||||||
|
#include "stm32f4xx_hal_gpio_ex.h"
|
||||||
|
#else
|
||||||
|
#include "stm32f2xx_hal_gpio_ex.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Common GPIO initialization
|
||||||
|
void common_init_gpio(void){
|
||||||
|
// TODO: Is this block actually doing something???
|
||||||
|
// pull low to hold ESP in reset??
|
||||||
|
// enable OTG out tied to ground
|
||||||
|
GPIOA->ODR = 0;
|
||||||
|
GPIOB->ODR = 0;
|
||||||
|
GPIOA->PUPDR = 0;
|
||||||
|
GPIOB->AFR[0] = 0;
|
||||||
|
GPIOB->AFR[1] = 0;
|
||||||
|
|
||||||
|
// C2: Voltage sense line
|
||||||
|
set_gpio_mode(GPIOC, 2, MODE_ANALOG);
|
||||||
|
|
||||||
|
// A11,A12: USB
|
||||||
|
set_gpio_alternate(GPIOA, 11, GPIO_AF10_OTG_FS);
|
||||||
|
set_gpio_alternate(GPIOA, 12, GPIO_AF10_OTG_FS);
|
||||||
|
GPIOA->OSPEEDR = GPIO_OSPEEDER_OSPEEDR11 | GPIO_OSPEEDER_OSPEEDR12;
|
||||||
|
|
||||||
|
// A9,A10: USART 1 for talking to the ESP / GPS
|
||||||
|
set_gpio_alternate(GPIOA, 9, GPIO_AF7_USART1);
|
||||||
|
set_gpio_alternate(GPIOA, 10, GPIO_AF7_USART1);
|
||||||
|
|
||||||
|
// B8,B9: CAN 1
|
||||||
|
#ifdef STM32F4
|
||||||
|
set_gpio_alternate(GPIOB, 8, GPIO_AF8_CAN1);
|
||||||
|
set_gpio_alternate(GPIOB, 9, GPIO_AF8_CAN1);
|
||||||
|
#else
|
||||||
|
set_gpio_alternate(GPIOB, 8, GPIO_AF9_CAN1);
|
||||||
|
set_gpio_alternate(GPIOB, 9, GPIO_AF9_CAN1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Peripheral initialization
|
||||||
|
void peripherals_init(void){
|
||||||
|
// enable GPIOB, UART2, CAN, USB clock
|
||||||
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
||||||
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
|
||||||
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
|
||||||
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
|
||||||
|
|
||||||
|
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
|
||||||
|
#ifdef PANDA
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_UART5EN;
|
||||||
|
#endif
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_CAN1EN;
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_CAN2EN;
|
||||||
|
#ifdef CAN3
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_CAN3EN;
|
||||||
|
#endif
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // main counter
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // slow loop and pedal
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt
|
||||||
|
//RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
|
||||||
|
//RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||||
|
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
|
||||||
|
//RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detection with internal pullup
|
||||||
|
#define PULL_EFFECTIVE_DELAY 10
|
||||||
|
bool detect_with_pull(GPIO_TypeDef *GPIO, int pin, int mode) {
|
||||||
|
set_gpio_mode(GPIO, pin, MODE_INPUT);
|
||||||
|
set_gpio_pullup(GPIO, pin, mode);
|
||||||
|
for (volatile int i=0; i<PULL_EFFECTIVE_DELAY; i++);
|
||||||
|
bool ret = get_gpio_input(GPIO, pin);
|
||||||
|
set_gpio_pullup(GPIO, pin, PULL_NONE);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// ////////// //
|
||||||
|
// Grey Panda //
|
||||||
|
// ////////// //
|
||||||
|
|
||||||
|
// Most hardware functionality is similar to white panda
|
||||||
|
const board board_grey = {
|
||||||
|
.board_type = "Grey",
|
||||||
|
.harness_config = &white_harness_config,
|
||||||
|
.init = white_init,
|
||||||
|
.enable_can_transciever = white_enable_can_transciever,
|
||||||
|
.enable_can_transcievers = white_enable_can_transcievers,
|
||||||
|
.set_led = white_set_led,
|
||||||
|
.set_usb_power_mode = white_set_usb_power_mode,
|
||||||
|
.set_esp_gps_mode = white_set_esp_gps_mode,
|
||||||
|
.set_can_mode = white_set_can_mode,
|
||||||
|
.usb_power_mode_tick = white_usb_power_mode_tick,
|
||||||
|
.check_ignition = white_check_ignition
|
||||||
|
};
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// ///// //
|
||||||
|
// Pedal //
|
||||||
|
// ///// //
|
||||||
|
|
||||||
|
void pedal_enable_can_transciever(uint8_t transciever, bool enabled) {
|
||||||
|
switch (transciever){
|
||||||
|
case 1:
|
||||||
|
set_gpio_output(GPIOB, 3, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Invalid CAN transciever ("); puth(transciever); puts("): enabling failed\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_enable_can_transcievers(bool enabled) {
|
||||||
|
pedal_enable_can_transciever(1U, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_set_led(uint8_t color, bool enabled) {
|
||||||
|
switch (color){
|
||||||
|
case LED_RED:
|
||||||
|
set_gpio_output(GPIOB, 10, !enabled);
|
||||||
|
break;
|
||||||
|
case LED_GREEN:
|
||||||
|
set_gpio_output(GPIOB, 11, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_set_usb_power_mode(uint8_t mode){
|
||||||
|
usb_power_mode = mode;
|
||||||
|
puts("Trying to set USB power mode on pedal. This is not supported.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_set_esp_gps_mode(uint8_t mode) {
|
||||||
|
UNUSED(mode);
|
||||||
|
puts("Trying to set ESP/GPS mode on pedal. This is not supported.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_set_can_mode(uint8_t mode){
|
||||||
|
switch (mode) {
|
||||||
|
case CAN_MODE_NORMAL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_usb_power_mode_tick(uint64_t tcnt){
|
||||||
|
UNUSED(tcnt);
|
||||||
|
// Not applicable
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pedal_check_ignition(void){
|
||||||
|
// not supported on pedal
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pedal_init(void) {
|
||||||
|
common_init_gpio();
|
||||||
|
|
||||||
|
// C0, C1: Throttle inputs
|
||||||
|
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
||||||
|
set_gpio_mode(GPIOC, 1, MODE_ANALOG);
|
||||||
|
// DAC outputs on A4 and A5
|
||||||
|
// apparently they don't need GPIO setup
|
||||||
|
|
||||||
|
// Enable transciever
|
||||||
|
pedal_enable_can_transcievers(true);
|
||||||
|
|
||||||
|
// Disable LEDs
|
||||||
|
pedal_set_led(LED_RED, false);
|
||||||
|
pedal_set_led(LED_GREEN, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const harness_configuration pedal_harness_config = {
|
||||||
|
.has_harness = false
|
||||||
|
};
|
||||||
|
|
||||||
|
const board board_pedal = {
|
||||||
|
.board_type = "Pedal",
|
||||||
|
.harness_config = &pedal_harness_config,
|
||||||
|
.init = pedal_init,
|
||||||
|
.enable_can_transciever = pedal_enable_can_transciever,
|
||||||
|
.enable_can_transcievers = pedal_enable_can_transcievers,
|
||||||
|
.set_led = pedal_set_led,
|
||||||
|
.set_usb_power_mode = pedal_set_usb_power_mode,
|
||||||
|
.set_esp_gps_mode = pedal_set_esp_gps_mode,
|
||||||
|
.set_can_mode = pedal_set_can_mode,
|
||||||
|
.usb_power_mode_tick = pedal_usb_power_mode_tick,
|
||||||
|
.check_ignition = pedal_check_ignition,
|
||||||
|
};
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
// /////////// //
|
||||||
|
// White Panda //
|
||||||
|
// /////////// //
|
||||||
|
|
||||||
|
void white_enable_can_transciever(uint8_t transciever, bool enabled) {
|
||||||
|
switch (transciever){
|
||||||
|
case 1U:
|
||||||
|
set_gpio_output(GPIOC, 1, !enabled);
|
||||||
|
break;
|
||||||
|
case 2U:
|
||||||
|
set_gpio_output(GPIOC, 13, !enabled);
|
||||||
|
break;
|
||||||
|
case 3U:
|
||||||
|
set_gpio_output(GPIOA, 0, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Invalid CAN transciever ("); puth(transciever); puts("): enabling failed\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_enable_can_transcievers(bool enabled) {
|
||||||
|
for(uint8_t i=1; i<=3U; i++)
|
||||||
|
white_enable_can_transciever(i, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_set_led(uint8_t color, bool enabled) {
|
||||||
|
switch (color){
|
||||||
|
case LED_RED:
|
||||||
|
set_gpio_output(GPIOC, 9, !enabled);
|
||||||
|
break;
|
||||||
|
case LED_GREEN:
|
||||||
|
set_gpio_output(GPIOC, 7, !enabled);
|
||||||
|
break;
|
||||||
|
case LED_BLUE:
|
||||||
|
set_gpio_output(GPIOC, 6, !enabled);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_set_usb_power_mode(uint8_t mode){
|
||||||
|
bool valid_mode = true;
|
||||||
|
switch (mode) {
|
||||||
|
case USB_POWER_CLIENT:
|
||||||
|
// B2,A13: set client mode
|
||||||
|
set_gpio_output(GPIOB, 2, 0);
|
||||||
|
set_gpio_output(GPIOA, 13, 1);
|
||||||
|
break;
|
||||||
|
case USB_POWER_CDP:
|
||||||
|
// B2,A13: set CDP mode
|
||||||
|
set_gpio_output(GPIOB, 2, 1);
|
||||||
|
set_gpio_output(GPIOA, 13, 1);
|
||||||
|
break;
|
||||||
|
case USB_POWER_DCP:
|
||||||
|
// B2,A13: set DCP mode on the charger (breaks USB!)
|
||||||
|
set_gpio_output(GPIOB, 2, 0);
|
||||||
|
set_gpio_output(GPIOA, 13, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
valid_mode = false;
|
||||||
|
puts("Invalid usb power mode\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid_mode) {
|
||||||
|
usb_power_mode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_set_esp_gps_mode(uint8_t mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case ESP_GPS_DISABLED:
|
||||||
|
// ESP OFF
|
||||||
|
set_gpio_output(GPIOC, 14, 0);
|
||||||
|
set_gpio_output(GPIOC, 5, 0);
|
||||||
|
break;
|
||||||
|
case ESP_GPS_ENABLED:
|
||||||
|
// ESP ON
|
||||||
|
set_gpio_output(GPIOC, 14, 1);
|
||||||
|
set_gpio_output(GPIOC, 5, 1);
|
||||||
|
break;
|
||||||
|
case ESP_GPS_BOOTMODE:
|
||||||
|
set_gpio_output(GPIOC, 14, 1);
|
||||||
|
set_gpio_output(GPIOC, 5, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Invalid ESP/GPS mode\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_set_can_mode(uint8_t mode){
|
||||||
|
switch (mode) {
|
||||||
|
case CAN_MODE_NORMAL:
|
||||||
|
// B12,B13: disable GMLAN mode
|
||||||
|
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
||||||
|
|
||||||
|
// B3,B4: disable GMLAN mode
|
||||||
|
set_gpio_mode(GPIOB, 3, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 4, MODE_INPUT);
|
||||||
|
|
||||||
|
// B5,B6: normal CAN2 mode
|
||||||
|
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
||||||
|
|
||||||
|
// A8,A15: normal CAN3 mode
|
||||||
|
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||||
|
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||||
|
break;
|
||||||
|
case CAN_MODE_GMLAN_CAN2:
|
||||||
|
// B5,B6: disable CAN2 mode
|
||||||
|
set_gpio_mode(GPIOB, 5, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 6, MODE_INPUT);
|
||||||
|
|
||||||
|
// B3,B4: disable GMLAN mode
|
||||||
|
set_gpio_mode(GPIOB, 3, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 4, MODE_INPUT);
|
||||||
|
|
||||||
|
// B12,B13: GMLAN mode
|
||||||
|
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
|
||||||
|
|
||||||
|
// A8,A15: normal CAN3 mode
|
||||||
|
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||||
|
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||||
|
break;
|
||||||
|
case CAN_MODE_GMLAN_CAN3:
|
||||||
|
// A8,A15: disable CAN3 mode
|
||||||
|
set_gpio_mode(GPIOA, 8, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOA, 15, MODE_INPUT);
|
||||||
|
|
||||||
|
// B12,B13: disable GMLAN mode
|
||||||
|
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
||||||
|
|
||||||
|
// B3,B4: GMLAN mode
|
||||||
|
set_gpio_alternate(GPIOB, 3, GPIO_AF11_CAN3);
|
||||||
|
set_gpio_alternate(GPIOB, 4, GPIO_AF11_CAN3);
|
||||||
|
|
||||||
|
// B5,B6: normal CAN2 mode
|
||||||
|
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t marker = 0;
|
||||||
|
void white_usb_power_mode_tick(uint64_t tcnt){
|
||||||
|
#ifndef BOOTSTUB
|
||||||
|
#define CURRENT_THRESHOLD 0xF00U
|
||||||
|
#define CLICKS 5U // 5 seconds to switch modes
|
||||||
|
|
||||||
|
uint32_t current = adc_get(ADCCHAN_CURRENT);
|
||||||
|
|
||||||
|
// ~0x9a = 500 ma
|
||||||
|
// puth(current); puts("\n");
|
||||||
|
|
||||||
|
switch (usb_power_mode) {
|
||||||
|
case USB_POWER_CLIENT:
|
||||||
|
if ((tcnt - marker) >= CLICKS) {
|
||||||
|
if (!is_enumerated) {
|
||||||
|
puts("USBP: didn't enumerate, switching to CDP mode\n");
|
||||||
|
// switch to CDP
|
||||||
|
white_set_usb_power_mode(USB_POWER_CDP);
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// keep resetting the timer if it's enumerated
|
||||||
|
if (is_enumerated) {
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case USB_POWER_CDP:
|
||||||
|
// On the EON, if we get into CDP mode we stay here. No need to go to DCP.
|
||||||
|
#ifndef EON
|
||||||
|
// been CLICKS clicks since we switched to CDP
|
||||||
|
if ((tcnt-marker) >= CLICKS) {
|
||||||
|
// measure current draw, if positive and no enumeration, switch to DCP
|
||||||
|
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
|
||||||
|
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
|
||||||
|
white_set_usb_power_mode(USB_POWER_DCP);
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// keep resetting the timer if there's no current draw in CDP
|
||||||
|
if (current >= CURRENT_THRESHOLD) {
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case USB_POWER_DCP:
|
||||||
|
// been at least CLICKS clicks since we switched to DCP
|
||||||
|
if ((tcnt-marker) >= CLICKS) {
|
||||||
|
// if no current draw, switch back to CDP
|
||||||
|
if (current >= CURRENT_THRESHOLD) {
|
||||||
|
puts("USBP: no current draw, switching back to CDP mode\n");
|
||||||
|
white_set_usb_power_mode(USB_POWER_CDP);
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// keep resetting the timer if there's current draw in DCP
|
||||||
|
if (current < CURRENT_THRESHOLD) {
|
||||||
|
marker = tcnt;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
puts("USB power mode invalid\n"); // set_usb_power_mode prevents assigning invalid values
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
UNUSED(tcnt);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool white_check_ignition(void){
|
||||||
|
// ignition is on PA1
|
||||||
|
return !get_gpio_input(GPIOA, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void white_init(void) {
|
||||||
|
common_init_gpio();
|
||||||
|
|
||||||
|
// C3: current sense
|
||||||
|
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
||||||
|
|
||||||
|
// A1: started_alt
|
||||||
|
set_gpio_pullup(GPIOA, 1, PULL_UP);
|
||||||
|
|
||||||
|
// A2, A3: USART 2 for debugging
|
||||||
|
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
|
||||||
|
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
|
||||||
|
|
||||||
|
// A4, A5, A6, A7: SPI
|
||||||
|
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
|
||||||
|
set_gpio_alternate(GPIOA, 5, GPIO_AF5_SPI1);
|
||||||
|
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
|
||||||
|
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
|
||||||
|
|
||||||
|
// Set USB power mode
|
||||||
|
white_set_usb_power_mode(USB_POWER_CLIENT);
|
||||||
|
|
||||||
|
// B12: GMLAN, ignition sense, pull up
|
||||||
|
set_gpio_pullup(GPIOB, 12, PULL_UP);
|
||||||
|
|
||||||
|
/* GMLAN mode pins:
|
||||||
|
M0(B15) M1(B14) mode
|
||||||
|
=======================
|
||||||
|
0 0 sleep
|
||||||
|
1 0 100kbit
|
||||||
|
0 1 high voltage wakeup
|
||||||
|
1 1 33kbit (normal)
|
||||||
|
*/
|
||||||
|
set_gpio_output(GPIOB, 14, 1);
|
||||||
|
set_gpio_output(GPIOB, 15, 1);
|
||||||
|
|
||||||
|
// B7: K-line enable
|
||||||
|
set_gpio_output(GPIOB, 7, 1);
|
||||||
|
|
||||||
|
// C12, D2: Setup K-line (UART5)
|
||||||
|
set_gpio_alternate(GPIOC, 12, GPIO_AF8_UART5);
|
||||||
|
set_gpio_alternate(GPIOD, 2, GPIO_AF8_UART5);
|
||||||
|
set_gpio_pullup(GPIOD, 2, PULL_UP);
|
||||||
|
|
||||||
|
// L-line enable
|
||||||
|
set_gpio_output(GPIOA, 14, 1);
|
||||||
|
|
||||||
|
// C10, C11: L-Line setup (USART3)
|
||||||
|
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
|
||||||
|
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
|
||||||
|
set_gpio_pullup(GPIOC, 11, PULL_UP);
|
||||||
|
|
||||||
|
// Enable CAN transcievers
|
||||||
|
white_enable_can_transcievers(true);
|
||||||
|
|
||||||
|
// Disable LEDs
|
||||||
|
white_set_led(LED_RED, false);
|
||||||
|
white_set_led(LED_GREEN, false);
|
||||||
|
white_set_led(LED_BLUE, false);
|
||||||
|
|
||||||
|
// Set normal CAN mode
|
||||||
|
white_set_can_mode(CAN_MODE_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const harness_configuration white_harness_config = {
|
||||||
|
.has_harness = false
|
||||||
|
};
|
||||||
|
|
||||||
|
const board board_white = {
|
||||||
|
.board_type = "White",
|
||||||
|
.harness_config = &white_harness_config,
|
||||||
|
.init = white_init,
|
||||||
|
.enable_can_transciever = white_enable_can_transciever,
|
||||||
|
.enable_can_transcievers = white_enable_can_transcievers,
|
||||||
|
.set_led = white_set_led,
|
||||||
|
.set_usb_power_mode = white_set_usb_power_mode,
|
||||||
|
.set_esp_gps_mode = white_set_esp_gps_mode,
|
||||||
|
.set_can_mode = white_set_can_mode,
|
||||||
|
.usb_power_mode_tick = white_usb_power_mode_tick,
|
||||||
|
.check_ignition = white_check_ignition
|
||||||
|
};
|
||||||
+24
-11
@@ -12,15 +12,29 @@
|
|||||||
#include "stm32f2xx_hal_gpio_ex.h"
|
#include "stm32f2xx_hal_gpio_ex.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// default since there's no serial
|
// ******************** Prototypes ********************
|
||||||
void puts(const char *a) {}
|
void puts(const char *a){ UNUSED(a); }
|
||||||
void puth(unsigned int i) {}
|
void puth(unsigned int i){ UNUSED(i); }
|
||||||
|
void puth2(unsigned int i){ UNUSED(i); }
|
||||||
|
typedef struct board board;
|
||||||
|
typedef struct harness_configuration harness_configuration;
|
||||||
|
// No CAN support on bootloader
|
||||||
|
void can_flip_buses(uint8_t bus1, uint8_t bus2){UNUSED(bus1); UNUSED(bus2);}
|
||||||
|
void can_set_obd(int harness_orientation, bool obd){UNUSED(harness_orientation); UNUSED(obd);}
|
||||||
|
|
||||||
|
// ********************* Globals **********************
|
||||||
|
int hw_type = 0;
|
||||||
|
const board *current_board;
|
||||||
|
|
||||||
|
// ********************* Includes *********************
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#include "provision.h"
|
#include "provision.h"
|
||||||
|
|
||||||
#include "drivers/clock.h"
|
#include "drivers/clock.h"
|
||||||
#include "drivers/llgpio.h"
|
#include "drivers/llgpio.h"
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
#include "drivers/spi.h"
|
#include "drivers/spi.h"
|
||||||
@@ -34,11 +48,11 @@ void puth(unsigned int i) {}
|
|||||||
|
|
||||||
#include "spi_flasher.h"
|
#include "spi_flasher.h"
|
||||||
|
|
||||||
void __initialize_hardware_early() {
|
void __initialize_hardware_early(void) {
|
||||||
early();
|
early();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail() {
|
void fail(void) {
|
||||||
soft_flasher_start();
|
soft_flasher_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,14 +62,13 @@ extern void *_app_start[];
|
|||||||
// FIXME: sometimes your panda will fail flashing and will quickly blink a single Green LED
|
// FIXME: sometimes your panda will fail flashing and will quickly blink a single Green LED
|
||||||
// BOUNTY: $200 coupon on shop.comma.ai or $100 check.
|
// BOUNTY: $200 coupon on shop.comma.ai or $100 check.
|
||||||
|
|
||||||
int main() {
|
int main(void) {
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
clock_init();
|
clock_init();
|
||||||
detect();
|
detect_configuration();
|
||||||
|
detect_board_type();
|
||||||
|
|
||||||
if (revision == PANDA_REV_C) {
|
current_board->set_usb_power_mode(USB_POWER_CLIENT);
|
||||||
set_usb_power_mode(USB_POWER_CLIENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) {
|
if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) {
|
||||||
enter_bootloader_mode = 0;
|
enter_bootloader_mode = 0;
|
||||||
@@ -88,7 +101,7 @@ fail:
|
|||||||
return 0;
|
return 0;
|
||||||
good:
|
good:
|
||||||
// jump to flash
|
// jump to flash
|
||||||
((void(*)()) _app_start[1])();
|
((void(*)(void)) _app_start[1])();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ obj/$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/main.$(PROJ_NAME).o
|
|||||||
$(OBJCOPY) -v -O binary obj/$(PROJ_NAME).elf obj/code.bin
|
$(OBJCOPY) -v -O binary obj/$(PROJ_NAME).elf obj/code.bin
|
||||||
SETLEN=1 ../crypto/sign.py obj/code.bin $@ $(CERT)
|
SETLEN=1 ../crypto/sign.py obj/code.bin $@ $(CERT)
|
||||||
@BINSIZE=$$(du -b "obj/$(PROJ_NAME).bin" | cut -f 1) ; \
|
@BINSIZE=$$(du -b "obj/$(PROJ_NAME).bin" | cut -f 1) ; \
|
||||||
if [ $$BINSIZE -ge 32768 ]; then echo "ERROR obj/$(PROJ_NAME).bin is too big!"; exit 1; fi;
|
if [ $$BINSIZE -ge 49152 ]; then echo "ERROR obj/$(PROJ_NAME).bin is too big!"; exit 1; fi;
|
||||||
|
|
||||||
obj/bootstub.$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/bootstub.$(PROJ_NAME).o obj/sha.$(PROJ_NAME).o obj/rsa.$(PROJ_NAME).o
|
obj/bootstub.$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/bootstub.$(PROJ_NAME).o obj/sha.$(PROJ_NAME).o obj/rsa.$(PROJ_NAME).o
|
||||||
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^
|
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
#include "stm32f2xx.h"
|
#include "stm32f2xx.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define USB_VID 0xbbaa
|
#define USB_VID 0xbbaaU
|
||||||
|
|
||||||
#ifdef BOOTSTUB
|
#ifdef BOOTSTUB
|
||||||
#define USB_PID 0xddee
|
#define USB_PID 0xddeeU
|
||||||
#else
|
#else
|
||||||
#define USB_PID 0xddcc
|
#define USB_PID 0xddccU
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
__typeof__ (b) _b = (b); \
|
__typeof__ (b) _b = (b); \
|
||||||
(_a > _b) ? _a : _b; })
|
(_a > _b) ? _a : _b; })
|
||||||
|
|
||||||
#define MAX_RESP_LEN 0x40
|
#define MAX_RESP_LEN 0x40U
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ void adc_init(void) {
|
|||||||
ADC1->SMPR1 = ADC_SMPR1_SMP12 | ADC_SMPR1_SMP13;
|
ADC1->SMPR1 = ADC_SMPR1_SMP12 | ADC_SMPR1_SMP13;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t adc_get(int channel) {
|
uint32_t adc_get(unsigned int channel) {
|
||||||
// includes length
|
// includes length
|
||||||
//ADC1->SQR1 = 0;
|
//ADC1->SQR1 = 0;
|
||||||
|
|
||||||
|
|||||||
+102
-57
@@ -9,11 +9,14 @@ typedef struct {
|
|||||||
CAN_FIFOMailBox_TypeDef *elems;
|
CAN_FIFOMailBox_TypeDef *elems;
|
||||||
} can_ring;
|
} can_ring;
|
||||||
|
|
||||||
#define CAN_BUS_RET_FLAG 0x80
|
#define CAN_BUS_RET_FLAG 0x80U
|
||||||
#define CAN_BUS_NUM_MASK 0x7F
|
#define CAN_BUS_NUM_MASK 0x7FU
|
||||||
|
|
||||||
#define BUS_MAX 4
|
#define BUS_MAX 4U
|
||||||
|
|
||||||
|
uint32_t can_send_errs = 0;
|
||||||
|
uint32_t can_fwd_errs = 0;
|
||||||
|
uint32_t gmlan_send_errs = 0;
|
||||||
extern int can_live, pending_can_live;
|
extern int can_live, pending_can_live;
|
||||||
|
|
||||||
// must reinit after changing these
|
// must reinit after changing these
|
||||||
@@ -30,7 +33,6 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem);
|
|||||||
// end API
|
// end API
|
||||||
|
|
||||||
#define ALL_CAN_SILENT 0xFF
|
#define ALL_CAN_SILENT 0xFF
|
||||||
#define ALL_CAN_BUT_MAIN_SILENT 0xFE
|
|
||||||
#define ALL_CAN_LIVE 0
|
#define ALL_CAN_LIVE 0
|
||||||
|
|
||||||
int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT;
|
int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT;
|
||||||
@@ -63,8 +65,11 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
|||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
if (q->w_ptr != q->r_ptr) {
|
if (q->w_ptr != q->r_ptr) {
|
||||||
*elem = q->elems[q->r_ptr];
|
*elem = q->elems[q->r_ptr];
|
||||||
if ((q->r_ptr + 1) == q->fifo_size) q->r_ptr = 0;
|
if ((q->r_ptr + 1U) == q->fifo_size) {
|
||||||
else q->r_ptr += 1;
|
q->r_ptr = 0;
|
||||||
|
} else {
|
||||||
|
q->r_ptr += 1U;
|
||||||
|
}
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
exit_critical_section();
|
exit_critical_section();
|
||||||
@@ -72,20 +77,23 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
bool can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
||||||
int ret = 0;
|
bool ret = false;
|
||||||
uint32_t next_w_ptr;
|
uint32_t next_w_ptr;
|
||||||
|
|
||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
if ((q->w_ptr + 1) == q->fifo_size) next_w_ptr = 0;
|
if ((q->w_ptr + 1U) == q->fifo_size) {
|
||||||
else next_w_ptr = q->w_ptr + 1;
|
next_w_ptr = 0;
|
||||||
|
} else {
|
||||||
|
next_w_ptr = q->w_ptr + 1U;
|
||||||
|
}
|
||||||
if (next_w_ptr != q->r_ptr) {
|
if (next_w_ptr != q->r_ptr) {
|
||||||
q->elems[q->w_ptr] = *elem;
|
q->elems[q->w_ptr] = *elem;
|
||||||
q->w_ptr = next_w_ptr;
|
q->w_ptr = next_w_ptr;
|
||||||
ret = 1;
|
ret = true;
|
||||||
}
|
}
|
||||||
exit_critical_section();
|
exit_critical_section();
|
||||||
if (ret == 0) {
|
if (!ret) {
|
||||||
can_overflow_cnt++;
|
can_overflow_cnt++;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("can_push failed!\n");
|
puts("can_push failed!\n");
|
||||||
@@ -130,7 +138,7 @@ void can_set_speed(uint8_t can_number) {
|
|||||||
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
|
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
|
||||||
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
|
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
|
||||||
|
|
||||||
if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, can_silent & (1 << can_number))) {
|
if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, (unsigned int)(can_silent) & (1U << can_number))) {
|
||||||
puts("CAN init FAILED!!!!!\n");
|
puts("CAN init FAILED!!!!!\n");
|
||||||
puth(can_number); puts(" ");
|
puth(can_number); puts(" ");
|
||||||
puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n");
|
puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n");
|
||||||
@@ -138,9 +146,8 @@ void can_set_speed(uint8_t can_number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void can_init(uint8_t can_number) {
|
void can_init(uint8_t can_number) {
|
||||||
if (can_number != 0xff) {
|
if (can_number != 0xffU) {
|
||||||
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
|
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
|
||||||
set_can_enable(CAN, 1);
|
|
||||||
can_set_speed(can_number);
|
can_set_speed(can_number);
|
||||||
|
|
||||||
llcan_init(CAN);
|
llcan_init(CAN);
|
||||||
@@ -156,48 +163,86 @@ void can_init_all(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void can_set_gmlan(int bus) {
|
void can_flip_buses(uint8_t bus1, uint8_t bus2){
|
||||||
if ((bus == -1) || (bus != can_num_lookup[3])) {
|
bus_lookup[bus1] = bus2;
|
||||||
// GMLAN OFF
|
bus_lookup[bus2] = bus1;
|
||||||
switch (can_num_lookup[3]) {
|
can_num_lookup[bus1] = bus2;
|
||||||
|
can_num_lookup[bus2] = bus1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Cleanup with new abstraction
|
||||||
|
void can_set_gmlan(uint8_t bus) {
|
||||||
|
if(hw_type != HW_TYPE_BLACK_PANDA){
|
||||||
|
// first, disable GMLAN on prev bus
|
||||||
|
uint8_t prev_bus = can_num_lookup[3];
|
||||||
|
if (bus != prev_bus) {
|
||||||
|
switch (prev_bus) {
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
puts("Disable GMLAN on CAN");
|
||||||
|
puth(prev_bus + 1U);
|
||||||
|
puts("\n");
|
||||||
|
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||||
|
bus_lookup[prev_bus] = prev_bus;
|
||||||
|
can_num_lookup[prev_bus] = prev_bus;
|
||||||
|
can_num_lookup[3] = -1;
|
||||||
|
can_init(prev_bus);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// GMLAN was not set on either BUS 1 or 2
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now enable GMLAN on the new bus
|
||||||
|
switch (bus) {
|
||||||
case 1:
|
case 1:
|
||||||
puts("disable GMLAN on CAN2\n");
|
|
||||||
set_can_mode(1, 0);
|
|
||||||
bus_lookup[1] = 1;
|
|
||||||
can_num_lookup[1] = 1;
|
|
||||||
can_num_lookup[3] = -1;
|
|
||||||
can_init(1);
|
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
puts("disable GMLAN on CAN3\n");
|
puts("Enable GMLAN on CAN");
|
||||||
set_can_mode(2, 0);
|
puth(bus + 1U);
|
||||||
bus_lookup[2] = 2;
|
puts("\n");
|
||||||
can_num_lookup[2] = 2;
|
current_board->set_can_mode((bus == 1U) ? CAN_MODE_GMLAN_CAN2 : CAN_MODE_GMLAN_CAN3);
|
||||||
can_num_lookup[3] = -1;
|
bus_lookup[bus] = 3;
|
||||||
can_init(2);
|
can_num_lookup[bus] = -1;
|
||||||
|
can_num_lookup[3] = bus;
|
||||||
|
can_init(bus);
|
||||||
|
break;
|
||||||
|
case 0xFF: //-1 unsigned
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
puts("GMLAN bus value invalid\n");
|
puts("GMLAN can only be set on CAN2 or CAN3\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
puts("GMLAN not available on black panda\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bus == 1) {
|
// TODO: remove
|
||||||
puts("GMLAN on CAN2\n");
|
void can_set_obd(uint8_t harness_orientation, bool obd){
|
||||||
// GMLAN on CAN2
|
if(obd){
|
||||||
set_can_mode(1, 1);
|
puts("setting CAN2 to be OBD\n");
|
||||||
bus_lookup[1] = 3;
|
} else {
|
||||||
can_num_lookup[1] = -1;
|
puts("setting CAN2 to be normal\n");
|
||||||
can_num_lookup[3] = 1;
|
}
|
||||||
can_init(1);
|
if(hw_type == HW_TYPE_BLACK_PANDA){
|
||||||
} else if (bus == 2) {
|
if(obd != (bool)(harness_orientation == HARNESS_STATUS_NORMAL)){
|
||||||
puts("GMLAN on CAN3\n");
|
// B5,B6: disable normal mode
|
||||||
// GMLAN on CAN3
|
set_gpio_mode(GPIOB, 5, MODE_INPUT);
|
||||||
set_can_mode(2, 1);
|
set_gpio_mode(GPIOB, 6, MODE_INPUT);
|
||||||
bus_lookup[2] = 3;
|
// B12,B13: CAN2 mode
|
||||||
can_num_lookup[2] = -1;
|
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
|
||||||
can_num_lookup[3] = 2;
|
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
|
||||||
can_init(2);
|
} else {
|
||||||
|
// B5,B6: CAN2 mode
|
||||||
|
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
||||||
|
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
||||||
|
// B12,B13: disable normal mode
|
||||||
|
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
||||||
|
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
puts("OBD CAN not available on non-black panda\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +277,7 @@ void can_sce(CAN_TypeDef *CAN) {
|
|||||||
// ***************************** CAN *****************************
|
// ***************************** CAN *****************************
|
||||||
|
|
||||||
void process_can(uint8_t can_number) {
|
void process_can(uint8_t can_number) {
|
||||||
if (can_number != 0xff) {
|
if (can_number != 0xffU) {
|
||||||
|
|
||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
|
|
||||||
@@ -249,10 +294,10 @@ void process_can(uint8_t can_number) {
|
|||||||
if ((CAN->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) {
|
if ((CAN->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) {
|
||||||
CAN_FIFOMailBox_TypeDef to_push;
|
CAN_FIFOMailBox_TypeDef to_push;
|
||||||
to_push.RIR = CAN->sTxMailBox[0].TIR;
|
to_push.RIR = CAN->sTxMailBox[0].TIR;
|
||||||
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000F) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
|
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000FU) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
|
||||||
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
|
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
|
||||||
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
|
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
|
||||||
can_push(&can_rx_q, &to_push);
|
can_send_errs += !can_push(&can_rx_q, &to_push);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) {
|
if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) {
|
||||||
@@ -320,8 +365,8 @@ void can_rx(uint8_t can_number) {
|
|||||||
|
|
||||||
safety_rx_hook(&to_push);
|
safety_rx_hook(&to_push);
|
||||||
|
|
||||||
set_led(LED_BLUE, 1);
|
current_board->set_led(LED_BLUE, true);
|
||||||
can_push(&can_rx_q, &to_push);
|
can_send_errs += !can_push(&can_rx_q, &to_push);
|
||||||
|
|
||||||
// next
|
// next
|
||||||
CAN->RF0R |= CAN_RF0R_RFOM0;
|
CAN->RF0R |= CAN_RF0R_RFOM0;
|
||||||
@@ -346,11 +391,11 @@ void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
|
|||||||
// add CAN packet to send queue
|
// add CAN packet to send queue
|
||||||
// bus number isn't passed through
|
// bus number isn't passed through
|
||||||
to_push->RDTR &= 0xF;
|
to_push->RDTR &= 0xF;
|
||||||
if ((bus_number == 3) && (can_num_lookup[3] == 0xFF)) {
|
if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) {
|
||||||
// TODO: why uint8 bro? only int8?
|
// TODO: why uint8 bro? only int8?
|
||||||
bitbang_gmlan(to_push);
|
gmlan_send_errs += !bitbang_gmlan(to_push);
|
||||||
} else {
|
} else {
|
||||||
can_push(can_queues[bus_number], to_push);
|
can_fwd_errs += !can_push(can_queues[bus_number], to_push);
|
||||||
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
|
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ void clock_init(void) {
|
|||||||
RCC->CR |= RCC_CR_HSEON;
|
RCC->CR |= RCC_CR_HSEON;
|
||||||
while ((RCC->CR & RCC_CR_HSERDY) == 0);
|
while ((RCC->CR & RCC_CR_HSERDY) == 0);
|
||||||
|
|
||||||
// divide shit
|
// divide things
|
||||||
RCC->CFGR = RCC_CFGR_HPRE_DIV1 | RCC_CFGR_PPRE2_DIV2 | RCC_CFGR_PPRE1_DIV4;
|
RCC->CFGR = RCC_CFGR_HPRE_DIV1 | RCC_CFGR_PPRE2_DIV2 | RCC_CFGR_PPRE1_DIV4;
|
||||||
|
|
||||||
// 16mhz crystal
|
// 16mhz crystal
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
void dac_init() {
|
void puth(unsigned int i);
|
||||||
|
void puts(const char *a);
|
||||||
|
|
||||||
|
void dac_init(void) {
|
||||||
// no buffers required since we have an opamp
|
// no buffers required since we have an opamp
|
||||||
//DAC->CR = DAC_CR_EN1 | DAC_CR_BOFF1 | DAC_CR_EN2 | DAC_CR_BOFF2;
|
//DAC->CR = DAC_CR_EN1 | DAC_CR_BOFF1 | DAC_CR_EN2 | DAC_CR_BOFF2;
|
||||||
DAC->DHR12R1 = 0;
|
DAC->DHR12R1 = 0;
|
||||||
@@ -11,6 +14,10 @@ void dac_set(int channel, uint32_t value) {
|
|||||||
DAC->DHR12R1 = value;
|
DAC->DHR12R1 = value;
|
||||||
} else if (channel == 1) {
|
} else if (channel == 1) {
|
||||||
DAC->DHR12R2 = value;
|
DAC->DHR12R2 = value;
|
||||||
|
} else {
|
||||||
|
puts("Failed to set DAC: invalid channel value: ");
|
||||||
|
puth(value);
|
||||||
|
puts("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,35 +41,38 @@ int do_bitstuff(char *out, char *in, int in_len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int append_crc(char *in, int in_len) {
|
int append_crc(char *in, int in_len) {
|
||||||
int crc = 0;
|
unsigned int crc = 0;
|
||||||
for (int i = 0; i < in_len; i++) {
|
for (int i = 0; i < in_len; i++) {
|
||||||
crc <<= 1;
|
crc <<= 1;
|
||||||
if ((in[i] ^ ((crc >> 15) & 1)) != 0) {
|
if (((unsigned int)(in[i]) ^ ((crc >> 15) & 1U)) != 0U) {
|
||||||
crc = crc ^ 0x4599;
|
crc = crc ^ 0x4599U;
|
||||||
}
|
}
|
||||||
crc &= 0x7fff;
|
crc &= 0x7fffU;
|
||||||
}
|
}
|
||||||
|
int in_len_copy = in_len;
|
||||||
for (int i = 14; i >= 0; i--) {
|
for (int i = 14; i >= 0; i--) {
|
||||||
in[in_len] = (crc>>i)&1;
|
in[in_len_copy] = (crc >> (unsigned int)(i)) & 1U;
|
||||||
in_len++;
|
in_len_copy++;
|
||||||
}
|
}
|
||||||
return in_len;
|
return in_len_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
int append_bits(char *in, int in_len, char *app, int app_len) {
|
int append_bits(char *in, int in_len, char *app, int app_len) {
|
||||||
|
int in_len_copy = in_len;
|
||||||
for (int i = 0; i < app_len; i++) {
|
for (int i = 0; i < app_len; i++) {
|
||||||
in[in_len] = app[i];
|
in[in_len_copy] = app[i];
|
||||||
in_len++;
|
in_len_copy++;
|
||||||
}
|
}
|
||||||
return in_len;
|
return in_len_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
int append_int(char *in, int in_len, int val, int val_len) {
|
int append_int(char *in, int in_len, int val, int val_len) {
|
||||||
for (int i = val_len-1; i >= 0; i--) {
|
int in_len_copy = in_len;
|
||||||
in[in_len] = (val&(1<<i)) != 0;
|
for (int i = val_len - 1; i >= 0; i--) {
|
||||||
in_len++;
|
in[in_len_copy] = ((unsigned int)(val) & (1U << (unsigned int)(i))) != 0U;
|
||||||
|
in_len_copy++;
|
||||||
}
|
}
|
||||||
return in_len;
|
return in_len_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
|
int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
|
||||||
@@ -92,7 +95,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
|
|||||||
// extended identifier
|
// extended identifier
|
||||||
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
|
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
|
||||||
len = append_int(pkt, len, 3, 2); // SRR+IDE
|
len = append_int(pkt, len, 3, 2); // SRR+IDE
|
||||||
len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1<<18)-1), 18); // Identifier
|
len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1U << 18) - 1U), 18); // Identifier
|
||||||
len = append_int(pkt, len, 0, 3); // RTR+r1+r0
|
len = append_int(pkt, len, 0, 3); // RTR+r1+r0
|
||||||
} else {
|
} else {
|
||||||
// standard identifier
|
// standard identifier
|
||||||
@@ -168,15 +171,16 @@ void reset_gmlan_switch_timeout(void) {
|
|||||||
|
|
||||||
void set_bitbanged_gmlan(int val) {
|
void set_bitbanged_gmlan(int val) {
|
||||||
if (val != 0) {
|
if (val != 0) {
|
||||||
GPIOB->ODR |= (1 << 13);
|
GPIOB->ODR |= (1U << 13);
|
||||||
} else {
|
} else {
|
||||||
GPIOB->ODR &= ~(1 << 13);
|
GPIOB->ODR &= ~(1U << 13);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char pkt_stuffed[MAX_BITS_CAN_PACKET];
|
char pkt_stuffed[MAX_BITS_CAN_PACKET];
|
||||||
int gmlan_sending = -1;
|
int gmlan_sending = -1;
|
||||||
int gmlan_sendmax = -1;
|
int gmlan_sendmax = -1;
|
||||||
|
bool gmlan_send_ok = true;
|
||||||
|
|
||||||
int gmlan_silent_count = 0;
|
int gmlan_silent_count = 0;
|
||||||
int gmlan_fail_count = 0;
|
int gmlan_fail_count = 0;
|
||||||
@@ -193,7 +197,7 @@ void TIM4_IRQHandler(void) {
|
|||||||
} else {
|
} else {
|
||||||
gmlan_silent_count++;
|
gmlan_silent_count++;
|
||||||
}
|
}
|
||||||
} else if (gmlan_silent_count == REQUIRED_SILENT_TIME) {
|
} else {
|
||||||
bool retry = 0;
|
bool retry = 0;
|
||||||
// in send loop
|
// in send loop
|
||||||
if ((gmlan_sending > 0) && // not first bit
|
if ((gmlan_sending > 0) && // not first bit
|
||||||
@@ -206,6 +210,8 @@ void TIM4_IRQHandler(void) {
|
|||||||
} else if ((read == 1) && (gmlan_sending == (gmlan_sendmax - 11))) { // recessive during ACK
|
} else if ((read == 1) && (gmlan_sending == (gmlan_sendmax - 11))) { // recessive during ACK
|
||||||
puts("GMLAN ERR: didn't recv ACK\n");
|
puts("GMLAN ERR: didn't recv ACK\n");
|
||||||
retry = 1;
|
retry = 1;
|
||||||
|
} else {
|
||||||
|
// do not retry
|
||||||
}
|
}
|
||||||
if (retry) {
|
if (retry) {
|
||||||
// reset sender (retry after 7 silent)
|
// reset sender (retry after 7 silent)
|
||||||
@@ -215,6 +221,7 @@ void TIM4_IRQHandler(void) {
|
|||||||
gmlan_fail_count++;
|
gmlan_fail_count++;
|
||||||
if (gmlan_fail_count == MAX_FAIL_COUNT) {
|
if (gmlan_fail_count == MAX_FAIL_COUNT) {
|
||||||
puts("GMLAN ERR: giving up send\n");
|
puts("GMLAN ERR: giving up send\n");
|
||||||
|
gmlan_send_ok = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);
|
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);
|
||||||
@@ -230,9 +237,7 @@ void TIM4_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TIM4->SR = 0;
|
TIM4->SR = 0;
|
||||||
} //bit bang mode
|
} else if (gmlan_alt_mode == GPIO_SWITCH) {
|
||||||
|
|
||||||
else if (gmlan_alt_mode == GPIO_SWITCH) {
|
|
||||||
if ((TIM4->SR & TIM_SR_UIF) && (gmlan_switch_below_timeout != -1)) {
|
if ((TIM4->SR & TIM_SR_UIF) && (gmlan_switch_below_timeout != -1)) {
|
||||||
if ((can_timeout_counter == 0) && gmlan_switch_timeout_enable) {
|
if ((can_timeout_counter == 0) && gmlan_switch_timeout_enable) {
|
||||||
//it has been more than 1 second since timeout was reset; disable timer and restore the GMLAN output
|
//it has been more than 1 second since timeout was reset; disable timer and restore the GMLAN output
|
||||||
@@ -255,25 +260,27 @@ void TIM4_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TIM4->SR = 0;
|
TIM4->SR = 0;
|
||||||
} //gmlan switch mode
|
} else {
|
||||||
|
puts("invalid gmlan_alt_mode\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
|
bool bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
|
||||||
|
gmlan_send_ok = true;
|
||||||
gmlan_alt_mode = BITBANG;
|
gmlan_alt_mode = BITBANG;
|
||||||
// TODO: make failure less silent
|
|
||||||
if (gmlan_sendmax == -1) {
|
|
||||||
|
|
||||||
|
if (gmlan_sendmax == -1) {
|
||||||
int len = get_bit_message(pkt_stuffed, to_bang);
|
int len = get_bit_message(pkt_stuffed, to_bang);
|
||||||
gmlan_fail_count = 0;
|
gmlan_fail_count = 0;
|
||||||
gmlan_silent_count = 0;
|
gmlan_silent_count = 0;
|
||||||
gmlan_sending = 0;
|
gmlan_sending = 0;
|
||||||
gmlan_sendmax = len;
|
gmlan_sendmax = len;
|
||||||
|
|
||||||
// setup for bitbang loop
|
// setup for bitbang loop
|
||||||
set_bitbanged_gmlan(1); // recessive
|
set_bitbanged_gmlan(1); // recessive
|
||||||
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);
|
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);
|
||||||
|
|
||||||
setup_timer4();
|
setup_timer4();
|
||||||
}
|
}
|
||||||
|
return gmlan_send_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
uint8_t car_harness_status = 0U;
|
||||||
|
#define HARNESS_STATUS_NC 0U
|
||||||
|
#define HARNESS_STATUS_NORMAL 1U
|
||||||
|
#define HARNESS_STATUS_FLIPPED 2U
|
||||||
|
|
||||||
|
// Threshold voltage (mV) for either of the SBUs to be below before deciding harness is connected
|
||||||
|
#define HARNESS_CONNECTED_THRESHOLD 2500U
|
||||||
|
|
||||||
|
struct harness_configuration {
|
||||||
|
const bool has_harness;
|
||||||
|
GPIO_TypeDef *GPIO_SBU1;
|
||||||
|
GPIO_TypeDef *GPIO_SBU2;
|
||||||
|
GPIO_TypeDef *GPIO_relay_normal;
|
||||||
|
GPIO_TypeDef *GPIO_relay_flipped;
|
||||||
|
uint8_t pin_SBU1;
|
||||||
|
uint8_t pin_SBU2;
|
||||||
|
uint8_t pin_relay_normal;
|
||||||
|
uint8_t pin_relay_flipped;
|
||||||
|
uint8_t adc_channel_SBU1;
|
||||||
|
uint8_t adc_channel_SBU2;
|
||||||
|
};
|
||||||
|
|
||||||
|
// this function will be the API for tici
|
||||||
|
void set_intercept_relay(bool intercept) {
|
||||||
|
if (car_harness_status != HARNESS_STATUS_NC) {
|
||||||
|
if (intercept) {
|
||||||
|
puts("switching harness to intercept (relay on)\n");
|
||||||
|
} else {
|
||||||
|
puts("switching harness to passthrough (relay off)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(car_harness_status == HARNESS_STATUS_NORMAL){
|
||||||
|
set_gpio_output(current_board->harness_config->GPIO_relay_normal, current_board->harness_config->pin_relay_normal, !intercept);
|
||||||
|
} else {
|
||||||
|
set_gpio_output(current_board->harness_config->GPIO_relay_flipped, current_board->harness_config->pin_relay_flipped, !intercept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool harness_check_ignition(void) {
|
||||||
|
bool ret = false;
|
||||||
|
switch(car_harness_status){
|
||||||
|
case HARNESS_STATUS_NORMAL:
|
||||||
|
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2);
|
||||||
|
break;
|
||||||
|
case HARNESS_STATUS_FLIPPED:
|
||||||
|
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: refactor to use harness config
|
||||||
|
void harness_setup_ignition_interrupts(void){
|
||||||
|
if(car_harness_status == HARNESS_STATUS_NORMAL){
|
||||||
|
SYSCFG->EXTICR[0] = SYSCFG_EXTICR1_EXTI3_PC;
|
||||||
|
EXTI->IMR |= (1U << 3);
|
||||||
|
EXTI->RTSR |= (1U << 3);
|
||||||
|
EXTI->FTSR |= (1U << 3);
|
||||||
|
puts("setup interrupts: normal\n");
|
||||||
|
} else if(car_harness_status == HARNESS_STATUS_FLIPPED) {
|
||||||
|
SYSCFG->EXTICR[0] = SYSCFG_EXTICR1_EXTI0_PC;
|
||||||
|
EXTI->IMR |= (1U << 0);
|
||||||
|
EXTI->RTSR |= (1U << 0);
|
||||||
|
EXTI->FTSR |= (1U << 0);
|
||||||
|
NVIC_EnableIRQ(EXTI1_IRQn);
|
||||||
|
puts("setup interrupts: flipped\n");
|
||||||
|
} else {
|
||||||
|
puts("tried to setup ignition interrupts without harness connected\n");
|
||||||
|
}
|
||||||
|
NVIC_EnableIRQ(EXTI0_IRQn);
|
||||||
|
NVIC_EnableIRQ(EXTI3_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t harness_detect_orientation(void) {
|
||||||
|
uint8_t ret = HARNESS_STATUS_NC;
|
||||||
|
|
||||||
|
#ifndef BOOTSTUB
|
||||||
|
uint32_t sbu1_voltage = adc_get(current_board->harness_config->adc_channel_SBU1);
|
||||||
|
uint32_t sbu2_voltage = adc_get(current_board->harness_config->adc_channel_SBU2);
|
||||||
|
|
||||||
|
// Detect connection and orientation
|
||||||
|
if((sbu1_voltage < HARNESS_CONNECTED_THRESHOLD) || (sbu2_voltage < HARNESS_CONNECTED_THRESHOLD)){
|
||||||
|
if (sbu1_voltage < sbu2_voltage) {
|
||||||
|
// orientation normal
|
||||||
|
ret = HARNESS_STATUS_NORMAL;
|
||||||
|
} else {
|
||||||
|
// orientation flipped
|
||||||
|
ret = HARNESS_STATUS_FLIPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void harness_init(void) {
|
||||||
|
// delay such that the connection is fully made before trying orientation detection
|
||||||
|
current_board->set_led(LED_BLUE, true);
|
||||||
|
delay(10000000);
|
||||||
|
current_board->set_led(LED_BLUE, false);
|
||||||
|
|
||||||
|
// try to detect orientation
|
||||||
|
uint8_t ret = harness_detect_orientation();
|
||||||
|
if (ret != HARNESS_STATUS_NC) {
|
||||||
|
puts("detected car harness with orientation "); puth2(ret); puts("\n");
|
||||||
|
car_harness_status = ret;
|
||||||
|
|
||||||
|
// set the SBU lines to be inputs before using the relay. The lines are not 5V tolerant in ADC mode!
|
||||||
|
set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT);
|
||||||
|
set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT);
|
||||||
|
|
||||||
|
// now we have orientation, set pin ignition detection
|
||||||
|
if(car_harness_status == HARNESS_STATUS_NORMAL){
|
||||||
|
set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT);
|
||||||
|
} else {
|
||||||
|
set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep busses connected by default
|
||||||
|
set_intercept_relay(false);
|
||||||
|
|
||||||
|
// setup ignition interrupts
|
||||||
|
harness_setup_ignition_interrupts();
|
||||||
|
} else {
|
||||||
|
puts("failed to detect car harness!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
-28
@@ -1,38 +1,48 @@
|
|||||||
// this is needed for 1 mbps support
|
// this is needed for 1 mbps support
|
||||||
#define CAN_QUANTA 8
|
#define CAN_QUANTA 8U
|
||||||
#define CAN_SEQ1 6 // roundf(quanta * 0.875f) - 1;
|
#define CAN_SEQ1 6 // roundf(quanta * 0.875f) - 1;
|
||||||
#define CAN_SEQ2 1 // roundf(quanta * 0.125f);
|
#define CAN_SEQ2 1 // roundf(quanta * 0.125f);
|
||||||
|
|
||||||
#define CAN_PCLK 24000
|
#define CAN_PCLK 24000U
|
||||||
// 333 = 33.3 kbps
|
// 333 = 33.3 kbps
|
||||||
// 5000 = 500 kbps
|
// 5000 = 500 kbps
|
||||||
#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10 / (x))
|
#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10U / (x))
|
||||||
|
|
||||||
bool llcan_set_speed(CAN_TypeDef *CAN, uint32_t speed, bool loopback, bool silent) {
|
#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF)
|
||||||
|
#define GET_LEN(msg) ((msg)->RDTR & 0xF)
|
||||||
|
#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21))
|
||||||
|
#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||||
|
#define GET_BYTES_04(msg) ((msg)->RDLR)
|
||||||
|
#define GET_BYTES_48(msg) ((msg)->RDHR)
|
||||||
|
|
||||||
|
void puts(const char *a);
|
||||||
|
|
||||||
|
bool llcan_set_speed(CAN_TypeDef *CAN_obj, uint32_t speed, bool loopback, bool silent) {
|
||||||
// initialization mode
|
// initialization mode
|
||||||
CAN->MCR = CAN_MCR_TTCM | CAN_MCR_INRQ;
|
CAN_obj->MCR = CAN_MCR_TTCM | CAN_MCR_INRQ;
|
||||||
while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK);
|
while((CAN_obj->MSR & CAN_MSR_INAK) != CAN_MSR_INAK);
|
||||||
|
|
||||||
// set time quanta from defines
|
// set time quanta from defines
|
||||||
CAN->BTR = (CAN_BTR_TS1_0 * (CAN_SEQ1-1)) |
|
CAN_obj->BTR = (CAN_BTR_TS1_0 * (CAN_SEQ1-1)) |
|
||||||
(CAN_BTR_TS2_0 * (CAN_SEQ2-1)) |
|
(CAN_BTR_TS2_0 * (CAN_SEQ2-1)) |
|
||||||
(can_speed_to_prescaler(speed) - 1);
|
(can_speed_to_prescaler(speed) - 1U);
|
||||||
|
|
||||||
// silent loopback mode for debugging
|
// silent loopback mode for debugging
|
||||||
if (loopback) {
|
if (loopback) {
|
||||||
CAN->BTR |= CAN_BTR_SILM | CAN_BTR_LBKM;
|
CAN_obj->BTR |= CAN_BTR_SILM | CAN_BTR_LBKM;
|
||||||
}
|
}
|
||||||
if (silent) {
|
if (silent) {
|
||||||
CAN->BTR |= CAN_BTR_SILM;
|
CAN_obj->BTR |= CAN_BTR_SILM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
CAN->MCR = CAN_MCR_TTCM | CAN_MCR_ABOM;
|
// cppcheck-suppress redundantAssignment ; it's a register
|
||||||
|
CAN_obj->MCR = CAN_MCR_TTCM | CAN_MCR_ABOM;
|
||||||
|
|
||||||
#define CAN_TIMEOUT 1000000
|
#define CAN_TIMEOUT 1000000
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
while(((CAN->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (tmp < CAN_TIMEOUT)) tmp++;
|
while(((CAN_obj->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (tmp < CAN_TIMEOUT)) tmp++;
|
||||||
if (tmp < CAN_TIMEOUT) {
|
if (tmp < CAN_TIMEOUT) {
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
@@ -40,42 +50,45 @@ bool llcan_set_speed(CAN_TypeDef *CAN, uint32_t speed, bool loopback, bool silen
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void llcan_init(CAN_TypeDef *CAN) {
|
void llcan_init(CAN_TypeDef *CAN_obj) {
|
||||||
// accept all filter
|
// accept all filter
|
||||||
CAN->FMR |= CAN_FMR_FINIT;
|
CAN_obj->FMR |= CAN_FMR_FINIT;
|
||||||
|
|
||||||
// no mask
|
// no mask
|
||||||
CAN->sFilterRegister[0].FR1 = 0;
|
CAN_obj->sFilterRegister[0].FR1 = 0;
|
||||||
CAN->sFilterRegister[0].FR2 = 0;
|
CAN_obj->sFilterRegister[0].FR2 = 0;
|
||||||
CAN->sFilterRegister[14].FR1 = 0;
|
CAN_obj->sFilterRegister[14].FR1 = 0;
|
||||||
CAN->sFilterRegister[14].FR2 = 0;
|
CAN_obj->sFilterRegister[14].FR2 = 0;
|
||||||
CAN->FA1R |= 1 | (1U << 14);
|
CAN_obj->FA1R |= 1U | (1U << 14);
|
||||||
|
|
||||||
CAN->FMR &= ~(CAN_FMR_FINIT);
|
CAN_obj->FMR &= ~(CAN_FMR_FINIT);
|
||||||
|
|
||||||
// enable certain CAN interrupts
|
// enable certain CAN interrupts
|
||||||
CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE;
|
CAN_obj->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE;
|
||||||
|
|
||||||
if (CAN == CAN1) {
|
if (CAN_obj == CAN1) {
|
||||||
NVIC_EnableIRQ(CAN1_TX_IRQn);
|
NVIC_EnableIRQ(CAN1_TX_IRQn);
|
||||||
NVIC_EnableIRQ(CAN1_RX0_IRQn);
|
NVIC_EnableIRQ(CAN1_RX0_IRQn);
|
||||||
NVIC_EnableIRQ(CAN1_SCE_IRQn);
|
NVIC_EnableIRQ(CAN1_SCE_IRQn);
|
||||||
} else if (CAN == CAN2) {
|
} else if (CAN_obj == CAN2) {
|
||||||
NVIC_EnableIRQ(CAN2_TX_IRQn);
|
NVIC_EnableIRQ(CAN2_TX_IRQn);
|
||||||
NVIC_EnableIRQ(CAN2_RX0_IRQn);
|
NVIC_EnableIRQ(CAN2_RX0_IRQn);
|
||||||
NVIC_EnableIRQ(CAN2_SCE_IRQn);
|
NVIC_EnableIRQ(CAN2_SCE_IRQn);
|
||||||
#ifdef CAN3
|
#ifdef CAN3
|
||||||
} else if (CAN == CAN3) {
|
} else if (CAN_obj == CAN3) {
|
||||||
NVIC_EnableIRQ(CAN3_TX_IRQn);
|
NVIC_EnableIRQ(CAN3_TX_IRQn);
|
||||||
NVIC_EnableIRQ(CAN3_RX0_IRQn);
|
NVIC_EnableIRQ(CAN3_RX0_IRQn);
|
||||||
NVIC_EnableIRQ(CAN3_SCE_IRQn);
|
NVIC_EnableIRQ(CAN3_SCE_IRQn);
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
puts("Invalid CAN: initialization failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void llcan_clear_send(CAN_TypeDef *CAN) {
|
void llcan_clear_send(CAN_TypeDef *CAN_obj) {
|
||||||
CAN->TSR |= CAN_TSR_ABRQ0;
|
CAN_obj->TSR |= CAN_TSR_ABRQ0;
|
||||||
CAN->MSR &= ~(CAN_MSR_ERRI);
|
CAN_obj->MSR &= ~(CAN_MSR_ERRI);
|
||||||
CAN->MSR = CAN->MSR;
|
// cppcheck-suppress selfAssignment ; needed to clear the register
|
||||||
|
CAN_obj->MSR = CAN_obj->MSR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,38 +7,49 @@
|
|||||||
#define PULL_UP 1
|
#define PULL_UP 1
|
||||||
#define PULL_DOWN 2
|
#define PULL_DOWN 2
|
||||||
|
|
||||||
void set_gpio_mode(GPIO_TypeDef *GPIO, int pin, int mode) {
|
#define OUTPUT_TYPE_PUSH_PULL 0U
|
||||||
|
#define OUTPUT_TYPE_OPEN_DRAIN 1U
|
||||||
|
|
||||||
|
void set_gpio_mode(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) {
|
||||||
uint32_t tmp = GPIO->MODER;
|
uint32_t tmp = GPIO->MODER;
|
||||||
tmp &= ~(3 << (pin*2));
|
tmp &= ~(3U << (pin * 2U));
|
||||||
tmp |= (mode << (pin*2));
|
tmp |= (mode << (pin * 2U));
|
||||||
GPIO->MODER = tmp;
|
GPIO->MODER = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_gpio_output(GPIO_TypeDef *GPIO, int pin, bool enabled) {
|
void set_gpio_output(GPIO_TypeDef *GPIO, unsigned int pin, bool enabled) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
GPIO->ODR |= (1 << pin);
|
GPIO->ODR |= (1U << pin);
|
||||||
} else {
|
} else {
|
||||||
GPIO->ODR &= ~(1 << pin);
|
GPIO->ODR &= ~(1U << pin);
|
||||||
}
|
}
|
||||||
set_gpio_mode(GPIO, pin, MODE_OUTPUT);
|
set_gpio_mode(GPIO, pin, MODE_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_gpio_alternate(GPIO_TypeDef *GPIO, int pin, int mode) {
|
void set_gpio_output_type(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int output_type){
|
||||||
uint32_t tmp = GPIO->AFR[pin>>3];
|
if(output_type == OUTPUT_TYPE_OPEN_DRAIN) {
|
||||||
tmp &= ~(0xF << ((pin&7)*4));
|
GPIO->OTYPER |= (1U << pin);
|
||||||
tmp |= mode << ((pin&7)*4);
|
} else {
|
||||||
GPIO->AFR[pin>>3] = tmp;
|
GPIO->OTYPER &= ~(1U << pin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_gpio_alternate(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) {
|
||||||
|
uint32_t tmp = GPIO->AFR[pin >> 3U];
|
||||||
|
tmp &= ~(0xFU << ((pin & 7U) * 4U));
|
||||||
|
tmp |= mode << ((pin & 7U) * 4U);
|
||||||
|
GPIO->AFR[pin >> 3] = tmp;
|
||||||
set_gpio_mode(GPIO, pin, MODE_ALTERNATE);
|
set_gpio_mode(GPIO, pin, MODE_ALTERNATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_gpio_pullup(GPIO_TypeDef *GPIO, int pin, int mode) {
|
void set_gpio_pullup(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) {
|
||||||
uint32_t tmp = GPIO->PUPDR;
|
uint32_t tmp = GPIO->PUPDR;
|
||||||
tmp &= ~(3 << (pin*2));
|
tmp &= ~(3U << (pin * 2U));
|
||||||
tmp |= (mode << (pin*2));
|
tmp |= (mode << (pin * 2U));
|
||||||
GPIO->PUPDR = tmp;
|
GPIO->PUPDR = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_gpio_input(GPIO_TypeDef *GPIO, int pin) {
|
int get_gpio_input(GPIO_TypeDef *GPIO, unsigned int pin) {
|
||||||
return (GPIO->IDR & (1U << pin)) == (1U << pin);
|
return (GPIO->IDR & (1U << pin)) == (1U << pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ void spi_init(void) {
|
|||||||
|
|
||||||
// setup interrupt on falling edge of SPI enable (on PA4)
|
// setup interrupt on falling edge of SPI enable (on PA4)
|
||||||
SYSCFG->EXTICR[2] = SYSCFG_EXTICR2_EXTI4_PA;
|
SYSCFG->EXTICR[2] = SYSCFG_EXTICR2_EXTI4_PA;
|
||||||
EXTI->IMR |= (1 << 4);
|
EXTI->IMR |= (1U << 4);
|
||||||
EXTI->FTSR |= (1 << 4);
|
EXTI->FTSR |= (1U << 4);
|
||||||
NVIC_EnableIRQ(EXTI4_IRQn);
|
NVIC_EnableIRQ(EXTI4_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ uint8_t spi_tx_buf[0x44];
|
|||||||
// SPI RX
|
// SPI RX
|
||||||
void DMA2_Stream2_IRQHandler(void) {
|
void DMA2_Stream2_IRQHandler(void) {
|
||||||
int *resp_len = (int*)spi_tx_buf;
|
int *resp_len = (int*)spi_tx_buf;
|
||||||
memset(spi_tx_buf, 0xaa, 0x44);
|
(void)memset(spi_tx_buf, 0xaa, 0x44);
|
||||||
*resp_len = spi_cb_rx(spi_buf, 0x14, spi_tx_buf+4);
|
*resp_len = spi_cb_rx(spi_buf, 0x14, spi_tx_buf+4);
|
||||||
#ifdef DEBUG_SPI
|
#ifdef DEBUG_SPI
|
||||||
puts("SPI write: ");
|
puts("SPI write: ");
|
||||||
@@ -113,12 +113,12 @@ void DMA2_Stream3_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EXTI4_IRQHandler(void) {
|
void EXTI4_IRQHandler(void) {
|
||||||
volatile int pr = EXTI->PR & (1 << 4);
|
volatile unsigned int pr = EXTI->PR & (1U << 4);
|
||||||
#ifdef DEBUG_SPI
|
#ifdef DEBUG_SPI
|
||||||
puts("exti4\n");
|
puts("exti4\n");
|
||||||
#endif
|
#endif
|
||||||
// SPI CS falling
|
// SPI CS falling
|
||||||
if ((pr & (1 << 4)) != 0) {
|
if ((pr & (1U << 4)) != 0U) {
|
||||||
spi_total_count = 0;
|
spi_total_count = 0;
|
||||||
spi_rx_dma(spi_buf, 0x14);
|
spi_rx_dma(spi_buf, 0x14);
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-30
@@ -1,6 +1,6 @@
|
|||||||
// IRQs: USART1, USART2, USART3, UART5
|
// IRQs: USART1, USART2, USART3, UART5
|
||||||
|
|
||||||
#define FIFO_SIZE 0x400
|
#define FIFO_SIZE 0x400U
|
||||||
typedef struct uart_ring {
|
typedef struct uart_ring {
|
||||||
volatile uint16_t w_ptr_tx;
|
volatile uint16_t w_ptr_tx;
|
||||||
volatile uint16_t r_ptr_tx;
|
volatile uint16_t r_ptr_tx;
|
||||||
@@ -81,7 +81,7 @@ void uart_ring_process(uart_ring *q) {
|
|||||||
if (q->w_ptr_tx != q->r_ptr_tx) {
|
if (q->w_ptr_tx != q->r_ptr_tx) {
|
||||||
if ((sr & USART_SR_TXE) != 0) {
|
if ((sr & USART_SR_TXE) != 0) {
|
||||||
q->uart->DR = q->elems_tx[q->r_ptr_tx];
|
q->uart->DR = q->elems_tx[q->r_ptr_tx];
|
||||||
q->r_ptr_tx = (q->r_ptr_tx + 1) % FIFO_SIZE;
|
q->r_ptr_tx = (q->r_ptr_tx + 1U) % FIFO_SIZE;
|
||||||
}
|
}
|
||||||
// there could be more to send
|
// there could be more to send
|
||||||
q->uart->CR1 |= USART_CR1_TXEIE;
|
q->uart->CR1 |= USART_CR1_TXEIE;
|
||||||
@@ -93,7 +93,7 @@ void uart_ring_process(uart_ring *q) {
|
|||||||
if ((sr & USART_SR_RXNE) || (sr & USART_SR_ORE)) {
|
if ((sr & USART_SR_RXNE) || (sr & USART_SR_ORE)) {
|
||||||
uint8_t c = q->uart->DR; // TODO: can drop packets
|
uint8_t c = q->uart->DR; // TODO: can drop packets
|
||||||
if (q != &esp_ring) {
|
if (q != &esp_ring) {
|
||||||
uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE;
|
uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE;
|
||||||
if (next_w_ptr != q->r_ptr_rx) {
|
if (next_w_ptr != q->r_ptr_rx) {
|
||||||
q->elems_rx[q->w_ptr_rx] = c;
|
q->elems_rx[q->w_ptr_rx] = c;
|
||||||
q->w_ptr_rx = next_w_ptr;
|
q->w_ptr_rx = next_w_ptr;
|
||||||
@@ -124,7 +124,7 @@ bool getc(uart_ring *q, char *elem) {
|
|||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
if (q->w_ptr_rx != q->r_ptr_rx) {
|
if (q->w_ptr_rx != q->r_ptr_rx) {
|
||||||
if (elem != NULL) *elem = q->elems_rx[q->r_ptr_rx];
|
if (elem != NULL) *elem = q->elems_rx[q->r_ptr_rx];
|
||||||
q->r_ptr_rx = (q->r_ptr_rx + 1) % FIFO_SIZE;
|
q->r_ptr_rx = (q->r_ptr_rx + 1U) % FIFO_SIZE;
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
exit_critical_section();
|
exit_critical_section();
|
||||||
@@ -137,7 +137,7 @@ bool injectc(uart_ring *q, char elem) {
|
|||||||
uint16_t next_w_ptr;
|
uint16_t next_w_ptr;
|
||||||
|
|
||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE;
|
next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE;
|
||||||
if (next_w_ptr != q->r_ptr_rx) {
|
if (next_w_ptr != q->r_ptr_rx) {
|
||||||
q->elems_rx[q->w_ptr_rx] = elem;
|
q->elems_rx[q->w_ptr_rx] = elem;
|
||||||
q->w_ptr_rx = next_w_ptr;
|
q->w_ptr_rx = next_w_ptr;
|
||||||
@@ -153,7 +153,7 @@ bool putc(uart_ring *q, char elem) {
|
|||||||
uint16_t next_w_ptr;
|
uint16_t next_w_ptr;
|
||||||
|
|
||||||
enter_critical_section();
|
enter_critical_section();
|
||||||
next_w_ptr = (q->w_ptr_tx + 1) % FIFO_SIZE;
|
next_w_ptr = (q->w_ptr_tx + 1U) % FIFO_SIZE;
|
||||||
if (next_w_ptr != q->r_ptr_tx) {
|
if (next_w_ptr != q->r_ptr_tx) {
|
||||||
q->elems_tx[q->w_ptr_tx] = elem;
|
q->elems_tx[q->w_ptr_tx] = elem;
|
||||||
q->w_ptr_tx = next_w_ptr;
|
q->w_ptr_tx = next_w_ptr;
|
||||||
@@ -195,17 +195,17 @@ void clear_uart_buff(uart_ring *q) {
|
|||||||
|
|
||||||
// ***************************** start UART code *****************************
|
// ***************************** start UART code *****************************
|
||||||
|
|
||||||
#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25) / (4 * (_BAUD_)))
|
#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25U) / (4U * (_BAUD_)))
|
||||||
#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100)
|
#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100U)
|
||||||
#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16) + 50) / 100)
|
#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U)
|
||||||
#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F))
|
#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
|
||||||
|
|
||||||
void uart_set_baud(USART_TypeDef *u, int baud) {
|
void uart_set_baud(USART_TypeDef *u, unsigned int baud) {
|
||||||
if (u == USART1) {
|
if (u == USART1) {
|
||||||
// USART1 is on APB2
|
// USART1 is on APB2
|
||||||
u->BRR = __USART_BRR(48000000, baud);
|
u->BRR = __USART_BRR(48000000U, baud);
|
||||||
} else {
|
} else {
|
||||||
u->BRR = __USART_BRR(24000000, baud);
|
u->BRR = __USART_BRR(24000000U, baud);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ void uart_dma_drain(void) {
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < (USART1_DMA_LEN - DMA2_Stream5->NDTR); i++) {
|
for (i = 0; i < (USART1_DMA_LEN - DMA2_Stream5->NDTR); i++) {
|
||||||
char c = usart1_dma[i];
|
char c = usart1_dma[i];
|
||||||
uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE;
|
uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE;
|
||||||
if (next_w_ptr != q->r_ptr_rx) {
|
if (next_w_ptr != q->r_ptr_rx) {
|
||||||
q->elems_rx[q->w_ptr_rx] = c;
|
q->elems_rx[q->w_ptr_rx] = c;
|
||||||
q->w_ptr_rx = next_w_ptr;
|
q->w_ptr_rx = next_w_ptr;
|
||||||
@@ -289,6 +289,8 @@ void uart_init(USART_TypeDef *u, int baud) {
|
|||||||
NVIC_EnableIRQ(USART3_IRQn);
|
NVIC_EnableIRQ(USART3_IRQn);
|
||||||
} else if (u == UART5) {
|
} else if (u == UART5) {
|
||||||
NVIC_EnableIRQ(UART5_IRQn);
|
NVIC_EnableIRQ(UART5_IRQn);
|
||||||
|
} else {
|
||||||
|
// USART type undefined, skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,49 +304,48 @@ void putch(const char a) {
|
|||||||
|
|
||||||
//putc(&debug_ring, a);
|
//putc(&debug_ring, a);
|
||||||
} else {
|
} else {
|
||||||
injectc(&debug_ring, a);
|
// misra-c2012-17.7: serial debug function, ok to ignore output
|
||||||
|
(void)injectc(&debug_ring, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void puts(const char *a) {
|
void puts(const char *a) {
|
||||||
for (;*a;a++) {
|
for (const char *in = a; *in; in++) {
|
||||||
if (*a == '\n') putch('\r');
|
if (*in == '\n') putch('\r');
|
||||||
putch(*a);
|
putch(*in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void putui(uint32_t i) {
|
void putui(uint32_t i) {
|
||||||
|
uint32_t i_copy = i;
|
||||||
char str[11];
|
char str[11];
|
||||||
uint8_t idx = 10;
|
uint8_t idx = 10;
|
||||||
str[idx] = '\0';
|
str[idx] = '\0';
|
||||||
idx--;
|
idx--;
|
||||||
do {
|
do {
|
||||||
str[idx] = (i % 10) + 0x30;
|
str[idx] = (i_copy % 10U) + 0x30U;
|
||||||
idx--;
|
idx--;
|
||||||
i /= 10;
|
i_copy /= 10;
|
||||||
} while (i != 0);
|
} while (i_copy != 0U);
|
||||||
puts(str + idx + 1);
|
puts(str + idx + 1U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puth(unsigned int i) {
|
void puth(unsigned int i) {
|
||||||
int pos;
|
|
||||||
char c[] = "0123456789abcdef";
|
char c[] = "0123456789abcdef";
|
||||||
for (pos = 28; pos != -4; pos -= 4) {
|
for (int pos = 28; pos != -4; pos -= 4) {
|
||||||
putch(c[(i >> pos) & 0xF]);
|
putch(c[(i >> (unsigned int)(pos)) & 0xFU]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void puth2(unsigned int i) {
|
void puth2(unsigned int i) {
|
||||||
int pos;
|
|
||||||
char c[] = "0123456789abcdef";
|
char c[] = "0123456789abcdef";
|
||||||
for (pos = 4; pos != -4; pos -= 4) {
|
for (int pos = 4; pos != -4; pos -= 4) {
|
||||||
putch(c[(i >> pos) & 0xF]);
|
putch(c[(i >> (unsigned int)(pos)) & 0xFU]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hexdump(const void *a, int l) {
|
void hexdump(const void *a, int l) {
|
||||||
int i;
|
for (int i=0; i < l; i++) {
|
||||||
for (i=0;i<l;i++) {
|
|
||||||
if ((i != 0) && ((i & 0xf) == 0)) puts("\n");
|
if ((i != 0) && ((i & 0xf) == 0)) puts("\n");
|
||||||
puth2(((const unsigned char*)a)[i]);
|
puth2(((const unsigned char*)a)[i]);
|
||||||
puts(" ");
|
puts(" ");
|
||||||
|
|||||||
+58
-54
@@ -25,9 +25,9 @@ USB_Setup_TypeDef;
|
|||||||
|
|
||||||
void usb_init(void);
|
void usb_init(void);
|
||||||
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired);
|
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired);
|
||||||
int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired);
|
int usb_cb_ep1_in(void *usbdata, int len, bool hardwired);
|
||||||
void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired);
|
void usb_cb_ep2_out(void *usbdata, int len, bool hardwired);
|
||||||
void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired);
|
void usb_cb_ep3_out(void *usbdata, int len, bool hardwired);
|
||||||
void usb_cb_enumeration_complete(void);
|
void usb_cb_enumeration_complete(void);
|
||||||
|
|
||||||
// **** supporting defines ****
|
// **** supporting defines ****
|
||||||
@@ -96,7 +96,7 @@ USB_OTG_GlobalTypeDef *USBx = USB_OTG_FS;
|
|||||||
#define STS_SETUP_COMP 4
|
#define STS_SETUP_COMP 4
|
||||||
#define STS_SETUP_UPDT 6
|
#define STS_SETUP_UPDT 6
|
||||||
|
|
||||||
#define USBD_FS_TRDT_VALUE 5
|
#define USBD_FS_TRDT_VALUE 5U
|
||||||
|
|
||||||
#define USB_OTG_SPEED_FULL 3
|
#define USB_OTG_SPEED_FULL 3
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ uint8_t resp[MAX_RESP_LEN];
|
|||||||
|
|
||||||
// Convert machine byte order to USB byte order
|
// Convert machine byte order to USB byte order
|
||||||
#define TOUSBORDER(num)\
|
#define TOUSBORDER(num)\
|
||||||
((num) & 0xFF), (((num) >> 8) & 0xFF)
|
((num) & 0xFFU), (((num) >> 8) & 0xFFU)
|
||||||
|
|
||||||
// take in string length and return the first 2 bytes of a string descriptor
|
// take in string length and return the first 2 bytes of a string descriptor
|
||||||
#define STRING_DESCRIPTOR_HEADER(size)\
|
#define STRING_DESCRIPTOR_HEADER(size)\
|
||||||
@@ -158,7 +158,7 @@ uint8_t device_qualifier[] = {
|
|||||||
|
|
||||||
uint8_t configuration_desc[] = {
|
uint8_t configuration_desc[] = {
|
||||||
DSCR_CONFIG_LEN, USB_DESC_TYPE_CONFIGURATION, // Length, Type,
|
DSCR_CONFIG_LEN, USB_DESC_TYPE_CONFIGURATION, // Length, Type,
|
||||||
TOUSBORDER(0x0045), // Total Len (uint16)
|
TOUSBORDER(0x0045U), // Total Len (uint16)
|
||||||
0x01, 0x01, STRING_OFFSET_ICONFIGURATION, // Num Interface, Config Value, Configuration
|
0x01, 0x01, STRING_OFFSET_ICONFIGURATION, // Num Interface, Config Value, Configuration
|
||||||
0xc0, 0x32, // Attributes, Max Power
|
0xc0, 0x32, // Attributes, Max Power
|
||||||
// interface 0 ALT 0
|
// interface 0 ALT 0
|
||||||
@@ -169,17 +169,17 @@ uint8_t configuration_desc[] = {
|
|||||||
// endpoint 1, read CAN
|
// endpoint 1, read CAN
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_RCV | 1, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
ENDPOINT_RCV | 1, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x00, // Polling Interval (NA)
|
0x00, // Polling Interval (NA)
|
||||||
// endpoint 2, send serial
|
// endpoint 2, send serial
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x00, // Polling Interval
|
0x00, // Polling Interval
|
||||||
// endpoint 3, send CAN
|
// endpoint 3, send CAN
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x00, // Polling Interval
|
0x00, // Polling Interval
|
||||||
// interface 0 ALT 1
|
// interface 0 ALT 1
|
||||||
DSCR_INTERFACE_LEN, USB_DESC_TYPE_INTERFACE, // Length, Type
|
DSCR_INTERFACE_LEN, USB_DESC_TYPE_INTERFACE, // Length, Type
|
||||||
@@ -189,17 +189,17 @@ uint8_t configuration_desc[] = {
|
|||||||
// endpoint 1, read CAN
|
// endpoint 1, read CAN
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_RCV | 1, ENDPOINT_TYPE_INT, // Endpoint Num/Direction, Type
|
ENDPOINT_RCV | 1, ENDPOINT_TYPE_INT, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x05, // Polling Interval (5 frames)
|
0x05, // Polling Interval (5 frames)
|
||||||
// endpoint 2, send serial
|
// endpoint 2, send serial
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x00, // Polling Interval
|
0x00, // Polling Interval
|
||||||
// endpoint 3, send CAN
|
// endpoint 3, send CAN
|
||||||
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type
|
||||||
ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type
|
||||||
TOUSBORDER(0x0040), // Max Packet (0x0040)
|
TOUSBORDER(0x0040U), // Max Packet (0x0040)
|
||||||
0x00, // Polling Interval
|
0x00, // Polling Interval
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -394,36 +394,36 @@ int current_int0_alt_setting = 0;
|
|||||||
// packet read and write
|
// packet read and write
|
||||||
|
|
||||||
void *USB_ReadPacket(void *dest, uint16_t len) {
|
void *USB_ReadPacket(void *dest, uint16_t len) {
|
||||||
uint32_t i=0;
|
uint32_t *dest_copy = (uint32_t *)dest;
|
||||||
uint32_t count32b = (len + 3) / 4;
|
uint32_t count32b = (len + 3U) / 4U;
|
||||||
|
|
||||||
for ( i = 0; i < count32b; i++) {
|
for (uint32_t i = 0; i < count32b; i++) {
|
||||||
// packed?
|
*dest_copy = USBx_DFIFO(0);
|
||||||
*(__attribute__((__packed__)) uint32_t *)dest = USBx_DFIFO(0);
|
dest_copy++;
|
||||||
dest += 4;
|
|
||||||
}
|
}
|
||||||
return ((void *)dest);
|
return ((void *)dest_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) {
|
void USB_WritePacket(const void *src, uint16_t len, uint32_t ep) {
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts("writing ");
|
puts("writing ");
|
||||||
hexdump(src, len);
|
hexdump(src, len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t numpacket = (len+(MAX_RESP_LEN-1))/MAX_RESP_LEN;
|
uint8_t numpacket = (len + (MAX_RESP_LEN - 1U)) / MAX_RESP_LEN;
|
||||||
uint32_t count32b = 0, i = 0;
|
uint32_t count32b = 0;
|
||||||
count32b = (len + 3) / 4;
|
count32b = (len + 3U) / 4U;
|
||||||
|
|
||||||
// bullshit
|
// TODO: revisit this
|
||||||
USBx_INEP(ep)->DIEPTSIZ = ((numpacket << 19) & USB_OTG_DIEPTSIZ_PKTCNT) |
|
USBx_INEP(ep)->DIEPTSIZ = ((numpacket << 19) & USB_OTG_DIEPTSIZ_PKTCNT) |
|
||||||
(len & USB_OTG_DIEPTSIZ_XFRSIZ);
|
(len & USB_OTG_DIEPTSIZ_XFRSIZ);
|
||||||
USBx_INEP(ep)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
|
USBx_INEP(ep)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
|
||||||
|
|
||||||
// load the FIFO
|
// load the FIFO
|
||||||
for (i = 0; i < count32b; i++) {
|
const uint32_t *src_copy = (const uint32_t *)src;
|
||||||
USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src);
|
for (uint32_t i = 0; i < count32b; i++) {
|
||||||
src += 4;
|
USBx_DFIFO(ep) = *src_copy;
|
||||||
|
src_copy++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,10 +471,10 @@ void usb_reset(void) {
|
|||||||
USBx->GRXFSIZ = 0x40;
|
USBx->GRXFSIZ = 0x40;
|
||||||
|
|
||||||
// 0x100 to offset past GRXFSIZ
|
// 0x100 to offset past GRXFSIZ
|
||||||
USBx->DIEPTXF0_HNPTXFSIZ = (0x40 << 16) | 0x40;
|
USBx->DIEPTXF0_HNPTXFSIZ = (0x40U << 16) | 0x40U;
|
||||||
|
|
||||||
// EP1, massive
|
// EP1, massive
|
||||||
USBx->DIEPTXF[0] = (0x40 << 16) | 0x80;
|
USBx->DIEPTXF[0] = (0x40U << 16) | 0x80U;
|
||||||
|
|
||||||
// flush TX fifo
|
// flush TX fifo
|
||||||
USBx->GRSTCTL = USB_OTG_GRSTCTL_TXFFLSH | USB_OTG_GRSTCTL_TXFNUM_4;
|
USBx->GRSTCTL = USB_OTG_GRSTCTL_TXFFLSH | USB_OTG_GRSTCTL_TXFNUM_4;
|
||||||
@@ -487,7 +487,7 @@ void usb_reset(void) {
|
|||||||
USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK;
|
USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK;
|
||||||
|
|
||||||
// ready to receive setup packets
|
// ready to receive setup packets
|
||||||
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) | (3 * 8);
|
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19)) | (3U << 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
char to_hex_char(int a) {
|
char to_hex_char(int a) {
|
||||||
@@ -506,17 +506,17 @@ void usb_setup(void) {
|
|||||||
switch (setup.b.bRequest) {
|
switch (setup.b.bRequest) {
|
||||||
case USB_REQ_SET_CONFIGURATION:
|
case USB_REQ_SET_CONFIGURATION:
|
||||||
// enable other endpoints, has to be here?
|
// enable other endpoints, has to be here?
|
||||||
USBx_INEP(1)->DIEPCTL = (0x40 & USB_OTG_DIEPCTL_MPSIZ) | (2 << 18) | (1 << 22) |
|
USBx_INEP(1)->DIEPCTL = (0x40U & USB_OTG_DIEPCTL_MPSIZ) | (2U << 18) | (1U << 22) |
|
||||||
USB_OTG_DIEPCTL_SD0PID_SEVNFRM | USB_OTG_DIEPCTL_USBAEP;
|
USB_OTG_DIEPCTL_SD0PID_SEVNFRM | USB_OTG_DIEPCTL_USBAEP;
|
||||||
USBx_INEP(1)->DIEPINT = 0xFF;
|
USBx_INEP(1)->DIEPINT = 0xFF;
|
||||||
|
|
||||||
USBx_OUTEP(2)->DOEPTSIZ = (1 << 19) | 0x40;
|
USBx_OUTEP(2)->DOEPTSIZ = (1U << 19) | 0x40U;
|
||||||
USBx_OUTEP(2)->DOEPCTL = (0x40 & USB_OTG_DOEPCTL_MPSIZ) | (2 << 18) |
|
USBx_OUTEP(2)->DOEPCTL = (0x40U & USB_OTG_DOEPCTL_MPSIZ) | (2U << 18) |
|
||||||
USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP;
|
USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP;
|
||||||
USBx_OUTEP(2)->DOEPINT = 0xFF;
|
USBx_OUTEP(2)->DOEPINT = 0xFF;
|
||||||
|
|
||||||
USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40;
|
USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U;
|
||||||
USBx_OUTEP(3)->DOEPCTL = (0x40 & USB_OTG_DOEPCTL_MPSIZ) | (2 << 18) |
|
USBx_OUTEP(3)->DOEPCTL = (0x40U & USB_OTG_DOEPCTL_MPSIZ) | (2U << 18) |
|
||||||
USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP;
|
USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP;
|
||||||
USBx_OUTEP(3)->DOEPINT = 0xFF;
|
USBx_OUTEP(3)->DOEPINT = 0xFF;
|
||||||
|
|
||||||
@@ -529,7 +529,7 @@ void usb_setup(void) {
|
|||||||
break;
|
break;
|
||||||
case USB_REQ_SET_ADDRESS:
|
case USB_REQ_SET_ADDRESS:
|
||||||
// set now?
|
// set now?
|
||||||
USBx_DEVICE->DCFG |= ((setup.b.wValue.w & 0x7f) << 4);
|
USBx_DEVICE->DCFG |= ((setup.b.wValue.w & 0x7fU) << 4);
|
||||||
|
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" set address\n");
|
puts(" set address\n");
|
||||||
@@ -575,16 +575,16 @@ void usb_setup(void) {
|
|||||||
break;
|
break;
|
||||||
case STRING_OFFSET_ISERIAL:
|
case STRING_OFFSET_ISERIAL:
|
||||||
#ifdef UID_BASE
|
#ifdef UID_BASE
|
||||||
resp[0] = 0x02 + 12*4;
|
resp[0] = 0x02 + (12 * 4);
|
||||||
resp[1] = 0x03;
|
resp[1] = 0x03;
|
||||||
|
|
||||||
// 96 bits = 12 bytes
|
// 96 bits = 12 bytes
|
||||||
for (int i = 0; i < 12; i++){
|
for (int i = 0; i < 12; i++){
|
||||||
uint8_t cc = ((uint8_t *)UID_BASE)[i];
|
uint8_t cc = ((uint8_t *)UID_BASE)[i];
|
||||||
resp[2 + i*4 + 0] = to_hex_char((cc>>4)&0xF);
|
resp[2 + (i * 4) + 0] = to_hex_char((cc >> 4) & 0xFU);
|
||||||
resp[2 + i*4 + 1] = '\0';
|
resp[2 + (i * 4) + 1] = '\0';
|
||||||
resp[2 + i*4 + 2] = to_hex_char((cc>>0)&0xF);
|
resp[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU);
|
||||||
resp[2 + i*4 + 3] = '\0';
|
resp[2 + (i * 4) + 3] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0);
|
USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0);
|
||||||
@@ -683,7 +683,7 @@ void usb_init(void) {
|
|||||||
USBx->GUSBCFG = USB_OTG_GUSBCFG_PHYSEL | USB_OTG_GUSBCFG_FDMOD;
|
USBx->GUSBCFG = USB_OTG_GUSBCFG_PHYSEL | USB_OTG_GUSBCFG_FDMOD;
|
||||||
|
|
||||||
// slowest timings
|
// slowest timings
|
||||||
USBx->GUSBCFG |= (uint32_t)((USBD_FS_TRDT_VALUE << 10) & USB_OTG_GUSBCFG_TRDT);
|
USBx->GUSBCFG |= ((USBD_FS_TRDT_VALUE << 10) & USB_OTG_GUSBCFG_TRDT);
|
||||||
|
|
||||||
// power up the PHY
|
// power up the PHY
|
||||||
#ifdef STM32F4
|
#ifdef STM32F4
|
||||||
@@ -732,7 +732,6 @@ void usb_init(void) {
|
|||||||
USBx->GAHBCFG = USB_OTG_GAHBCFG_GINT;
|
USBx->GAHBCFG = USB_OTG_GAHBCFG_GINT;
|
||||||
|
|
||||||
// DCTL startup value is 2 on new chip, 0 on old chip
|
// DCTL startup value is 2 on new chip, 0 on old chip
|
||||||
// THIS IS FUCKING BULLSHIT
|
|
||||||
USBx_DEVICE->DCTL = 0;
|
USBx_DEVICE->DCTL = 0;
|
||||||
|
|
||||||
// enable the IRQ
|
// enable the IRQ
|
||||||
@@ -793,21 +792,22 @@ void usb_irqhandler(void) {
|
|||||||
if ((gintsts & USB_OTG_GINTSTS_RXFLVL) != 0) {
|
if ((gintsts & USB_OTG_GINTSTS_RXFLVL) != 0) {
|
||||||
// 1. Read the Receive status pop register
|
// 1. Read the Receive status pop register
|
||||||
volatile unsigned int rxst = USBx->GRXSTSP;
|
volatile unsigned int rxst = USBx->GRXSTSP;
|
||||||
|
int status = (rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17;
|
||||||
|
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" RX FIFO:");
|
puts(" RX FIFO:");
|
||||||
puth(rxst);
|
puth(rxst);
|
||||||
puts(" status: ");
|
puts(" status: ");
|
||||||
puth((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17);
|
puth(status);
|
||||||
puts(" len: ");
|
puts(" len: ");
|
||||||
puth((rxst & USB_OTG_GRXSTSP_BCNT) >> 4);
|
puth((rxst & USB_OTG_GRXSTSP_BCNT) >> 4);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT) {
|
if (status == STS_DATA_UPDT) {
|
||||||
int endpoint = (rxst & USB_OTG_GRXSTSP_EPNUM);
|
int endpoint = (rxst & USB_OTG_GRXSTSP_EPNUM);
|
||||||
int len = (rxst & USB_OTG_GRXSTSP_BCNT) >> 4;
|
int len = (rxst & USB_OTG_GRXSTSP_BCNT) >> 4;
|
||||||
USB_ReadPacket(&usbdata, len);
|
(void)USB_ReadPacket(&usbdata, len);
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" data ");
|
puts(" data ");
|
||||||
puth(len);
|
puth(len);
|
||||||
@@ -822,13 +822,15 @@ void usb_irqhandler(void) {
|
|||||||
if (endpoint == 3) {
|
if (endpoint == 3) {
|
||||||
usb_cb_ep3_out(usbdata, len, 1);
|
usb_cb_ep3_out(usbdata, len, 1);
|
||||||
}
|
}
|
||||||
} else if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT) {
|
} else if (status == STS_SETUP_UPDT) {
|
||||||
USB_ReadPacket(&setup, 8);
|
(void)USB_ReadPacket(&setup, 8);
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" setup ");
|
puts(" setup ");
|
||||||
hexdump(&setup, 8);
|
hexdump(&setup, 8);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
// status is neither STS_DATA_UPDT or STS_SETUP_UPDT, skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,7 +884,7 @@ void usb_irqhandler(void) {
|
|||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" OUT2 PACKET XFRC\n");
|
puts(" OUT2 PACKET XFRC\n");
|
||||||
#endif
|
#endif
|
||||||
USBx_OUTEP(2)->DOEPTSIZ = (1 << 19) | 0x40;
|
USBx_OUTEP(2)->DOEPTSIZ = (1U << 19) | 0x40U;
|
||||||
USBx_OUTEP(2)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
|
USBx_OUTEP(2)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,24 +892,26 @@ void usb_irqhandler(void) {
|
|||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" OUT3 PACKET XFRC\n");
|
puts(" OUT3 PACKET XFRC\n");
|
||||||
#endif
|
#endif
|
||||||
USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40;
|
USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U;
|
||||||
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
|
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
|
||||||
} else if ((USBx_OUTEP(3)->DOEPINT & 0x2000) != 0) {
|
} else if ((USBx_OUTEP(3)->DOEPINT & 0x2000) != 0) {
|
||||||
#ifdef DEBUG_USB
|
#ifdef DEBUG_USB
|
||||||
puts(" OUT3 PACKET WTF\n");
|
puts(" OUT3 PACKET WTF\n");
|
||||||
#endif
|
#endif
|
||||||
// if NAK was set trigger this, unknown interrupt
|
// if NAK was set trigger this, unknown interrupt
|
||||||
USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40;
|
USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U;
|
||||||
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
||||||
} else if ((USBx_OUTEP(3)->DOEPINT) != 0) {
|
} else if ((USBx_OUTEP(3)->DOEPINT) != 0) {
|
||||||
puts("OUTEP3 error ");
|
puts("OUTEP3 error ");
|
||||||
puth(USBx_OUTEP(3)->DOEPINT);
|
puth(USBx_OUTEP(3)->DOEPINT);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
|
} else {
|
||||||
|
// USBx_OUTEP(3)->DOEPINT is 0, ok to skip
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((USBx_OUTEP(0)->DOEPINT & USB_OTG_DIEPINT_XFRC) != 0) {
|
if ((USBx_OUTEP(0)->DOEPINT & USB_OTG_DIEPINT_XFRC) != 0) {
|
||||||
// ready for next packet
|
// ready for next packet
|
||||||
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) | (1 * 8);
|
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19)) | (1U << 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// respond to setup packets
|
// respond to setup packets
|
||||||
@@ -978,12 +982,12 @@ void usb_irqhandler(void) {
|
|||||||
puts(" IN PACKET QUEUE\n");
|
puts(" IN PACKET QUEUE\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((ep0_txlen != 0) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40)) {
|
if ((ep0_txlen != 0U) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40U)) {
|
||||||
uint16_t len = MIN(ep0_txlen, 0x40);
|
uint16_t len = MIN(ep0_txlen, 0x40);
|
||||||
USB_WritePacket(ep0_txdata, len, 0);
|
USB_WritePacket(ep0_txdata, len, 0);
|
||||||
ep0_txdata += len;
|
ep0_txdata += len;
|
||||||
ep0_txlen -= len;
|
ep0_txlen -= len;
|
||||||
if (ep0_txlen == 0) {
|
if (ep0_txlen == 0U) {
|
||||||
ep0_txdata = NULL;
|
ep0_txdata = NULL;
|
||||||
USBx_DEVICE->DIEPEMPMSK &= ~1;
|
USBx_DEVICE->DIEPEMPMSK &= ~1;
|
||||||
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
||||||
|
|||||||
+12
-385
@@ -1,377 +1,4 @@
|
|||||||
// this is last place with ifdef PANDA
|
// Early bringup
|
||||||
|
|
||||||
#ifdef STM32F4
|
|
||||||
#include "stm32f4xx_hal_gpio_ex.h"
|
|
||||||
#else
|
|
||||||
#include "stm32f2xx_hal_gpio_ex.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ********************* dynamic configuration detection *********************
|
|
||||||
|
|
||||||
#define PANDA_REV_AB 0
|
|
||||||
#define PANDA_REV_C 1
|
|
||||||
|
|
||||||
#define PULL_EFFECTIVE_DELAY 10
|
|
||||||
|
|
||||||
void puts(const char *a);
|
|
||||||
|
|
||||||
bool has_external_debug_serial = 0;
|
|
||||||
bool is_giant_panda = 0;
|
|
||||||
bool is_entering_bootmode = 0;
|
|
||||||
int revision = PANDA_REV_AB;
|
|
||||||
bool is_grey_panda = 0;
|
|
||||||
|
|
||||||
bool detect_with_pull(GPIO_TypeDef *GPIO, int pin, int mode) {
|
|
||||||
set_gpio_mode(GPIO, pin, MODE_INPUT);
|
|
||||||
set_gpio_pullup(GPIO, pin, mode);
|
|
||||||
for (volatile int i=0; i<PULL_EFFECTIVE_DELAY; i++);
|
|
||||||
bool ret = get_gpio_input(GPIO, pin);
|
|
||||||
set_gpio_pullup(GPIO, pin, PULL_NONE);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// must call again from main because BSS is zeroed
|
|
||||||
void detect(void) {
|
|
||||||
// detect has_external_debug_serial
|
|
||||||
has_external_debug_serial = detect_with_pull(GPIOA, 3, PULL_DOWN);
|
|
||||||
|
|
||||||
#ifdef PANDA
|
|
||||||
// detect is_giant_panda
|
|
||||||
is_giant_panda = detect_with_pull(GPIOB, 1, PULL_DOWN);
|
|
||||||
|
|
||||||
// detect panda REV C.
|
|
||||||
// A13 floats in REV AB. In REV C, A13 is pulled up to 5V with a 10K
|
|
||||||
// resistor and attached to the USB power control chip CTRL
|
|
||||||
// line. Pulling A13 down with an internal 50k resistor in REV C
|
|
||||||
// will produce a voltage divider that results in a high logic
|
|
||||||
// level. Checking if this pin reads high with a pull down should
|
|
||||||
// differentiate REV AB from C.
|
|
||||||
revision = detect_with_pull(GPIOA, 13, PULL_DOWN) ? PANDA_REV_C : PANDA_REV_AB;
|
|
||||||
|
|
||||||
// check if the ESP is trying to put me in boot mode
|
|
||||||
is_entering_bootmode = !detect_with_pull(GPIOB, 0, PULL_UP);
|
|
||||||
|
|
||||||
// check if it's a grey panda by seeing if the SPI lines are floating
|
|
||||||
// TODO: is this reliable?
|
|
||||||
is_grey_panda = !(detect_with_pull(GPIOA, 4, PULL_DOWN) | detect_with_pull(GPIOA, 5, PULL_DOWN) | detect_with_pull(GPIOA, 6, PULL_DOWN) | detect_with_pull(GPIOA, 7, PULL_DOWN));
|
|
||||||
#else
|
|
||||||
// need to do this for early detect
|
|
||||||
is_giant_panda = 0;
|
|
||||||
is_grey_panda = 0;
|
|
||||||
revision = PANDA_REV_AB;
|
|
||||||
is_entering_bootmode = 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// ********************* bringup *********************
|
|
||||||
|
|
||||||
void periph_init(void) {
|
|
||||||
// enable GPIOB, UART2, CAN, USB clock
|
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
|
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
|
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
|
|
||||||
|
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
|
|
||||||
#ifdef PANDA
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_UART5EN;
|
|
||||||
#endif
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_CAN1EN;
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_CAN2EN;
|
|
||||||
#ifdef CAN3
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_CAN3EN;
|
|
||||||
#endif
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // main counter
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // slow loop and pedal
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt
|
|
||||||
//RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
|
|
||||||
//RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
|
||||||
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
|
|
||||||
//RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ********************* setters *********************
|
|
||||||
|
|
||||||
void set_can_enable(CAN_TypeDef *CAN, bool enabled) {
|
|
||||||
// enable CAN busses
|
|
||||||
if (CAN == CAN1) {
|
|
||||||
#ifdef PANDA
|
|
||||||
// CAN1_EN
|
|
||||||
set_gpio_output(GPIOC, 1, !enabled);
|
|
||||||
#else
|
|
||||||
#ifdef PEDAL
|
|
||||||
// CAN1_EN (not flipped)
|
|
||||||
set_gpio_output(GPIOB, 3, !enabled);
|
|
||||||
#else
|
|
||||||
// CAN1_EN
|
|
||||||
set_gpio_output(GPIOB, 3, enabled);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
} else if (CAN == CAN2) {
|
|
||||||
#ifdef PANDA
|
|
||||||
// CAN2_EN
|
|
||||||
set_gpio_output(GPIOC, 13, !enabled);
|
|
||||||
#else
|
|
||||||
// CAN2_EN
|
|
||||||
set_gpio_output(GPIOB, 4, enabled);
|
|
||||||
#endif
|
|
||||||
#ifdef CAN3
|
|
||||||
} else if (CAN == CAN3) {
|
|
||||||
// CAN3_EN
|
|
||||||
set_gpio_output(GPIOA, 0, !enabled);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PANDA
|
|
||||||
#define LED_RED 9
|
|
||||||
#define LED_GREEN 7
|
|
||||||
#define LED_BLUE 6
|
|
||||||
#else
|
|
||||||
#define LED_RED 10
|
|
||||||
#define LED_GREEN 11
|
|
||||||
#define LED_BLUE -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void set_led(int led_num, int on) {
|
|
||||||
if (led_num != -1) {
|
|
||||||
#ifdef PANDA
|
|
||||||
set_gpio_output(GPIOC, led_num, !on);
|
|
||||||
#else
|
|
||||||
set_gpio_output(GPIOB, led_num, !on);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_can_mode(int can, bool use_gmlan) {
|
|
||||||
// connects to CAN2 xcvr or GMLAN xcvr
|
|
||||||
if (use_gmlan) {
|
|
||||||
if (can == 1) {
|
|
||||||
// B5,B6: disable normal mode
|
|
||||||
set_gpio_mode(GPIOB, 5, MODE_INPUT);
|
|
||||||
set_gpio_mode(GPIOB, 6, MODE_INPUT);
|
|
||||||
|
|
||||||
// B12,B13: gmlan mode
|
|
||||||
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
|
|
||||||
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
|
|
||||||
#ifdef CAN3
|
|
||||||
} else if (can == 2) {
|
|
||||||
// A8,A15: disable normal mode
|
|
||||||
set_gpio_mode(GPIOA, 8, MODE_INPUT);
|
|
||||||
set_gpio_mode(GPIOA, 15, MODE_INPUT);
|
|
||||||
|
|
||||||
// B3,B4: enable gmlan mode
|
|
||||||
set_gpio_alternate(GPIOB, 3, GPIO_AF11_CAN3);
|
|
||||||
set_gpio_alternate(GPIOB, 4, GPIO_AF11_CAN3);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (can == 1) {
|
|
||||||
// B12,B13: disable gmlan mode
|
|
||||||
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
|
||||||
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
|
||||||
|
|
||||||
// B5,B6: normal mode
|
|
||||||
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
|
||||||
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
|
||||||
#ifdef CAN3
|
|
||||||
} else if (can == 2) {
|
|
||||||
// B3,B4: disable gmlan mode
|
|
||||||
set_gpio_mode(GPIOB, 3, MODE_INPUT);
|
|
||||||
set_gpio_mode(GPIOB, 4, MODE_INPUT);
|
|
||||||
// A8,A15: normal mode
|
|
||||||
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
|
||||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define USB_POWER_NONE 0
|
|
||||||
#define USB_POWER_CLIENT 1
|
|
||||||
#define USB_POWER_CDP 2
|
|
||||||
#define USB_POWER_DCP 3
|
|
||||||
|
|
||||||
int usb_power_mode = USB_POWER_NONE;
|
|
||||||
|
|
||||||
void set_usb_power_mode(int mode) {
|
|
||||||
bool valid_mode = true;
|
|
||||||
switch (mode) {
|
|
||||||
case USB_POWER_CLIENT:
|
|
||||||
// B2,A13: set client mode
|
|
||||||
set_gpio_output(GPIOB, 2, 0);
|
|
||||||
set_gpio_output(GPIOA, 13, 1);
|
|
||||||
break;
|
|
||||||
case USB_POWER_CDP:
|
|
||||||
// B2,A13: set CDP mode
|
|
||||||
set_gpio_output(GPIOB, 2, 1);
|
|
||||||
set_gpio_output(GPIOA, 13, 1);
|
|
||||||
break;
|
|
||||||
case USB_POWER_DCP:
|
|
||||||
// B2,A13: set DCP mode on the charger (breaks USB!)
|
|
||||||
set_gpio_output(GPIOB, 2, 0);
|
|
||||||
set_gpio_output(GPIOA, 13, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
valid_mode = false;
|
|
||||||
puts("Invalid usb power mode\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid_mode) {
|
|
||||||
usb_power_mode = mode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ESP_DISABLED 0
|
|
||||||
#define ESP_ENABLED 1
|
|
||||||
#define ESP_BOOTMODE 2
|
|
||||||
|
|
||||||
void set_esp_mode(int mode) {
|
|
||||||
switch (mode) {
|
|
||||||
case ESP_DISABLED:
|
|
||||||
// ESP OFF
|
|
||||||
set_gpio_output(GPIOC, 14, 0);
|
|
||||||
set_gpio_output(GPIOC, 5, 0);
|
|
||||||
break;
|
|
||||||
case ESP_ENABLED:
|
|
||||||
// ESP ON
|
|
||||||
set_gpio_output(GPIOC, 14, 1);
|
|
||||||
set_gpio_output(GPIOC, 5, 1);
|
|
||||||
break;
|
|
||||||
case ESP_BOOTMODE:
|
|
||||||
set_gpio_output(GPIOC, 14, 1);
|
|
||||||
set_gpio_output(GPIOC, 5, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
puts("Invalid esp mode\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ********************* big init function *********************
|
|
||||||
|
|
||||||
// board specific
|
|
||||||
void gpio_init(void) {
|
|
||||||
// pull low to hold ESP in reset??
|
|
||||||
// enable OTG out tied to ground
|
|
||||||
GPIOA->ODR = 0;
|
|
||||||
GPIOB->ODR = 0;
|
|
||||||
GPIOA->PUPDR = 0;
|
|
||||||
//GPIOC->ODR = 0;
|
|
||||||
GPIOB->AFR[0] = 0;
|
|
||||||
GPIOB->AFR[1] = 0;
|
|
||||||
|
|
||||||
// C2,C3: analog mode, voltage and current sense
|
|
||||||
set_gpio_mode(GPIOC, 2, MODE_ANALOG);
|
|
||||||
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
|
||||||
|
|
||||||
#ifdef PEDAL
|
|
||||||
// comma pedal has inputs on C0 and C1
|
|
||||||
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
|
||||||
set_gpio_mode(GPIOC, 1, MODE_ANALOG);
|
|
||||||
// DAC outputs on A4 and A5
|
|
||||||
// apparently they don't need GPIO setup
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// C8: FAN aka TIM3_CH4
|
|
||||||
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
|
||||||
|
|
||||||
// turn off LEDs and set mode
|
|
||||||
set_led(LED_RED, 0);
|
|
||||||
set_led(LED_GREEN, 0);
|
|
||||||
set_led(LED_BLUE, 0);
|
|
||||||
|
|
||||||
// A11,A12: USB
|
|
||||||
set_gpio_alternate(GPIOA, 11, GPIO_AF10_OTG_FS);
|
|
||||||
set_gpio_alternate(GPIOA, 12, GPIO_AF10_OTG_FS);
|
|
||||||
GPIOA->OSPEEDR = GPIO_OSPEEDER_OSPEEDR11 | GPIO_OSPEEDER_OSPEEDR12;
|
|
||||||
|
|
||||||
#ifdef PANDA
|
|
||||||
// enable started_alt on the panda
|
|
||||||
set_gpio_pullup(GPIOA, 1, PULL_UP);
|
|
||||||
|
|
||||||
// A2,A3: USART 2 for debugging
|
|
||||||
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
|
|
||||||
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
|
|
||||||
|
|
||||||
// A9,A10: USART 1 for talking to the ESP
|
|
||||||
set_gpio_alternate(GPIOA, 9, GPIO_AF7_USART1);
|
|
||||||
set_gpio_alternate(GPIOA, 10, GPIO_AF7_USART1);
|
|
||||||
|
|
||||||
// B12: GMLAN, ignition sense, pull up
|
|
||||||
set_gpio_pullup(GPIOB, 12, PULL_UP);
|
|
||||||
|
|
||||||
// A4,A5,A6,A7: setup SPI
|
|
||||||
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
|
|
||||||
set_gpio_alternate(GPIOA, 5, GPIO_AF5_SPI1);
|
|
||||||
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
|
|
||||||
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// B8,B9: CAN 1
|
|
||||||
#ifdef STM32F4
|
|
||||||
set_gpio_alternate(GPIOB, 8, GPIO_AF8_CAN1);
|
|
||||||
set_gpio_alternate(GPIOB, 9, GPIO_AF8_CAN1);
|
|
||||||
#else
|
|
||||||
set_gpio_alternate(GPIOB, 8, GPIO_AF9_CAN1);
|
|
||||||
set_gpio_alternate(GPIOB, 9, GPIO_AF9_CAN1);
|
|
||||||
#endif
|
|
||||||
set_can_enable(CAN1, 1);
|
|
||||||
|
|
||||||
// B5,B6: CAN 2
|
|
||||||
set_can_mode(1, 0);
|
|
||||||
set_can_enable(CAN2, 1);
|
|
||||||
|
|
||||||
// A8,A15: CAN 3
|
|
||||||
#ifdef CAN3
|
|
||||||
set_can_mode(2, 0);
|
|
||||||
set_can_enable(CAN3, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* GMLAN mode pins:
|
|
||||||
M0(B15) M1(B14) mode
|
|
||||||
=======================
|
|
||||||
0 0 sleep
|
|
||||||
1 0 100kbit
|
|
||||||
0 1 high voltage wakeup
|
|
||||||
1 1 33kbit (normal)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// put gmlan transceiver in normal mode
|
|
||||||
set_gpio_output(GPIOB, 14, 1);
|
|
||||||
set_gpio_output(GPIOB, 15, 1);
|
|
||||||
|
|
||||||
#ifdef PANDA
|
|
||||||
// K-line enable moved from B4->B7 to make room for GMLAN on CAN3
|
|
||||||
set_gpio_output(GPIOB, 7, 1); // REV C
|
|
||||||
|
|
||||||
// C12,D2: K-Line setup on UART 5
|
|
||||||
set_gpio_alternate(GPIOC, 12, GPIO_AF8_UART5);
|
|
||||||
set_gpio_alternate(GPIOD, 2, GPIO_AF8_UART5);
|
|
||||||
set_gpio_pullup(GPIOD, 2, PULL_UP);
|
|
||||||
|
|
||||||
// L-line enable
|
|
||||||
set_gpio_output(GPIOA, 14, 1);
|
|
||||||
|
|
||||||
// C10,C11: L-Line setup on USART 3
|
|
||||||
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
|
|
||||||
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
|
|
||||||
set_gpio_pullup(GPIOC, 11, PULL_UP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
set_usb_power_mode(USB_POWER_CLIENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ********************* early bringup *********************
|
|
||||||
|
|
||||||
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
|
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
|
||||||
#define ENTER_SOFTLOADER_MAGIC 0xdeadc0de
|
#define ENTER_SOFTLOADER_MAGIC 0xdeadc0de
|
||||||
#define BOOT_NORMAL 0xdeadb111
|
#define BOOT_NORMAL 0xdeadb111
|
||||||
@@ -404,9 +31,13 @@ void early(void) {
|
|||||||
// if wrong chip, reboot
|
// if wrong chip, reboot
|
||||||
volatile unsigned int id = DBGMCU->IDCODE;
|
volatile unsigned int id = DBGMCU->IDCODE;
|
||||||
#ifdef STM32F4
|
#ifdef STM32F4
|
||||||
if ((id&0xFFF) != 0x463) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
if ((id & 0xFFFU) != 0x463U) {
|
||||||
|
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if ((id&0xFFF) != 0x411) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
if ((id & 0xFFFU) != 0x411U) {
|
||||||
|
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// setup interrupt table
|
// setup interrupt table
|
||||||
@@ -419,25 +50,21 @@ void early(void) {
|
|||||||
GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0;
|
GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0;
|
||||||
GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0;
|
GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0;
|
||||||
|
|
||||||
detect();
|
detect_configuration();
|
||||||
|
detect_board_type();
|
||||||
|
|
||||||
#ifdef PANDA
|
#ifdef PANDA
|
||||||
// enable the ESP, disable ESP boot mode
|
// enable the ESP, disable ESP boot mode
|
||||||
// unless we are on a giant panda, then there's no ESP
|
|
||||||
// dont disable on grey panda
|
// dont disable on grey panda
|
||||||
if (is_giant_panda) {
|
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
|
||||||
set_esp_mode(ESP_DISABLED);
|
|
||||||
} else {
|
|
||||||
set_esp_mode(ESP_ENABLED);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
|
if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
|
||||||
#ifdef PANDA
|
#ifdef PANDA
|
||||||
set_esp_mode(ESP_DISABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
|
||||||
#endif
|
#endif
|
||||||
set_led(LED_GREEN, 1);
|
current_board->set_led(LED_GREEN, 1);
|
||||||
jump_to_bootloader();
|
jump_to_bootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-12
@@ -6,32 +6,36 @@ void delay(int a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *memset(void *str, int c, unsigned int n) {
|
void *memset(void *str, int c, unsigned int n) {
|
||||||
unsigned int i;
|
uint8_t *s = str;
|
||||||
for (i = 0; i < n; i++) {
|
for (unsigned int i = 0; i < n; i++) {
|
||||||
*((uint8_t*)str) = c;
|
*s = c;
|
||||||
++str;
|
s++;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memcpy(void *dest, const void *src, unsigned int n) {
|
void *memcpy(void *dest, const void *src, unsigned int n) {
|
||||||
unsigned int i;
|
uint8_t *d = dest;
|
||||||
// TODO: make not slow
|
const uint8_t *s = src;
|
||||||
for (i = 0; i < n; i++) {
|
for (unsigned int i = 0; i < n; i++) {
|
||||||
((uint8_t*)dest)[i] = *(uint8_t*)src;
|
*d = *s;
|
||||||
++src;
|
d++;
|
||||||
|
s++;
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
|
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
|
||||||
unsigned int i;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
for (i = 0; i < num; i++) {
|
const uint8_t *p1 = ptr1;
|
||||||
if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) {
|
const uint8_t *p2 = ptr2;
|
||||||
|
for (unsigned int i = 0; i < num; i++) {
|
||||||
|
if (*p1 != *p2) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
p1++;
|
||||||
|
p2++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
+257
-227
@@ -1,39 +1,44 @@
|
|||||||
//#define EON
|
//#define EON
|
||||||
|
//#define PANDA
|
||||||
|
|
||||||
|
// ********************* Includes *********************
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "obj/gitversion.h"
|
#include "obj/gitversion.h"
|
||||||
|
|
||||||
// ********************* includes *********************
|
|
||||||
|
|
||||||
|
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#include "provision.h"
|
#include "provision.h"
|
||||||
|
|
||||||
|
#include "main_declarations.h"
|
||||||
|
|
||||||
#include "drivers/llcan.h"
|
#include "drivers/llcan.h"
|
||||||
#include "drivers/llgpio.h"
|
#include "drivers/llgpio.h"
|
||||||
#include "gpio.h"
|
#include "drivers/adc.h"
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
#include "drivers/uart.h"
|
#include "drivers/uart.h"
|
||||||
#include "drivers/adc.h"
|
|
||||||
#include "drivers/usb.h"
|
#include "drivers/usb.h"
|
||||||
#include "drivers/gmlan_alt.h"
|
#include "drivers/gmlan_alt.h"
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
#include "drivers/clock.h"
|
#include "drivers/clock.h"
|
||||||
|
|
||||||
|
#include "gpio.h"
|
||||||
|
|
||||||
#ifndef EON
|
#ifndef EON
|
||||||
#include "drivers/spi.h"
|
#include "drivers/spi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "power_saving.h"
|
#include "power_saving.h"
|
||||||
#include "safety.h"
|
#include "safety.h"
|
||||||
|
|
||||||
#include "drivers/can.h"
|
#include "drivers/can.h"
|
||||||
|
|
||||||
// ********************* serial debugging *********************
|
// ********************* Serial debugging *********************
|
||||||
|
|
||||||
void debug_ring_callback(uart_ring *ring) {
|
void debug_ring_callback(uart_ring *ring) {
|
||||||
char rcv;
|
char rcv;
|
||||||
while (getc(ring, &rcv)) {
|
while (getc(ring, &rcv)) {
|
||||||
putc(ring, rcv);
|
(void)putc(ring, rcv); // misra-c2012-17.7: cast to void is ok: debug function
|
||||||
|
|
||||||
// jump to DFU flash
|
// jump to DFU flash
|
||||||
if (rcv == 'z') {
|
if (rcv == 'z') {
|
||||||
@@ -49,29 +54,23 @@ void debug_ring_callback(uart_ring *ring) {
|
|||||||
// enable CDP mode
|
// enable CDP mode
|
||||||
if (rcv == 'C') {
|
if (rcv == 'C') {
|
||||||
puts("switching USB to CDP mode\n");
|
puts("switching USB to CDP mode\n");
|
||||||
set_usb_power_mode(USB_POWER_CDP);
|
current_board->set_usb_power_mode(USB_POWER_CDP);
|
||||||
}
|
}
|
||||||
if (rcv == 'c') {
|
if (rcv == 'c') {
|
||||||
puts("switching USB to client mode\n");
|
puts("switching USB to client mode\n");
|
||||||
set_usb_power_mode(USB_POWER_CLIENT);
|
current_board->set_usb_power_mode(USB_POWER_CLIENT);
|
||||||
}
|
}
|
||||||
if (rcv == 'D') {
|
if (rcv == 'D') {
|
||||||
puts("switching USB to DCP mode\n");
|
puts("switching USB to DCP mode\n");
|
||||||
set_usb_power_mode(USB_POWER_DCP);
|
current_board->set_usb_power_mode(USB_POWER_DCP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************** started logic *****************************
|
// ***************************** started logic *****************************
|
||||||
|
void started_interrupt_handler(uint8_t interrupt_line) {
|
||||||
bool is_gpio_started(void) {
|
volatile unsigned int pr = EXTI->PR & (1U << interrupt_line);
|
||||||
// ignition is on PA1
|
if ((pr & (1U << interrupt_line)) != 0U) {
|
||||||
return (GPIOA->IDR & (1U << 1)) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EXTI1_IRQHandler(void) {
|
|
||||||
volatile int pr = EXTI->PR & (1U << 1);
|
|
||||||
if ((pr & (1U << 1)) != 0) {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("got started interrupt\n");
|
puts("got started interrupt\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -80,10 +79,25 @@ void EXTI1_IRQHandler(void) {
|
|||||||
delay(100000);
|
delay(100000);
|
||||||
|
|
||||||
// set power savings mode here
|
// set power savings mode here
|
||||||
int power_save_state = is_gpio_started() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
|
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
|
||||||
set_power_save_state(power_save_state);
|
set_power_save_state(power_save_state);
|
||||||
EXTI->PR = (1U << 1);
|
|
||||||
}
|
}
|
||||||
|
EXTI->PR = (1U << interrupt_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void EXTI0_IRQHandler(void) {
|
||||||
|
started_interrupt_handler(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void EXTI1_IRQHandler(void) {
|
||||||
|
started_interrupt_handler(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void EXTI3_IRQHandler(void) {
|
||||||
|
started_interrupt_handler(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void started_interrupt_init(void) {
|
void started_interrupt_init(void) {
|
||||||
@@ -94,17 +108,64 @@ void started_interrupt_init(void) {
|
|||||||
NVIC_EnableIRQ(EXTI1_IRQn);
|
NVIC_EnableIRQ(EXTI1_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ****************************** safety mode ******************************
|
||||||
|
|
||||||
|
// this is the only way to leave silent mode
|
||||||
|
void set_safety_mode(uint16_t mode, int16_t param) {
|
||||||
|
int err = safety_set_mode(mode, param);
|
||||||
|
if (err == -1) {
|
||||||
|
puts("Error: safety set mode failed\n");
|
||||||
|
} else {
|
||||||
|
if (mode == SAFETY_NOOUTPUT) {
|
||||||
|
can_silent = ALL_CAN_SILENT;
|
||||||
|
} else {
|
||||||
|
can_silent = ALL_CAN_LIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case SAFETY_NOOUTPUT:
|
||||||
|
set_intercept_relay(false);
|
||||||
|
if(hw_type == HW_TYPE_BLACK_PANDA){
|
||||||
|
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SAFETY_ELM327:
|
||||||
|
set_intercept_relay(false);
|
||||||
|
if(hw_type == HW_TYPE_BLACK_PANDA){
|
||||||
|
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
set_intercept_relay(true);
|
||||||
|
if(hw_type == HW_TYPE_BLACK_PANDA){
|
||||||
|
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (safety_ignition_hook() != -1) {
|
||||||
|
// if the ignition hook depends on something other than the started GPIO
|
||||||
|
// we have to disable power savings (fix for GM and Tesla)
|
||||||
|
set_power_save_state(POWER_SAVE_STATUS_DISABLED);
|
||||||
|
} else {
|
||||||
|
// power mode is already POWER_SAVE_STATUS_DISABLED and CAN TXs are active
|
||||||
|
}
|
||||||
|
can_init_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ***************************** USB port *****************************
|
// ***************************** USB port *****************************
|
||||||
|
|
||||||
int get_health_pkt(void *dat) {
|
int get_health_pkt(void *dat) {
|
||||||
struct __attribute__((packed)) {
|
struct __attribute__((packed)) {
|
||||||
uint32_t voltage;
|
uint32_t voltage_pkt;
|
||||||
uint32_t current;
|
uint32_t current_pkt;
|
||||||
uint8_t started;
|
uint32_t can_send_errs_pkt;
|
||||||
uint8_t controls_allowed;
|
uint32_t can_fwd_errs_pkt;
|
||||||
uint8_t gas_interceptor_detected;
|
uint32_t gmlan_send_errs_pkt;
|
||||||
uint8_t started_signal_detected;
|
uint8_t started_pkt;
|
||||||
uint8_t started_alt;
|
uint8_t controls_allowed_pkt;
|
||||||
|
uint8_t gas_interceptor_detected_pkt;
|
||||||
|
uint8_t car_harness_status_pkt;
|
||||||
} *health = dat;
|
} *health = dat;
|
||||||
|
|
||||||
//Voltage will be measured in mv. 5000 = 5V
|
//Voltage will be measured in mv. 5000 = 5V
|
||||||
@@ -117,29 +178,35 @@ int get_health_pkt(void *dat) {
|
|||||||
// s = 1000/((4095/3.3)*(1/11)) = 8.8623046875
|
// s = 1000/((4095/3.3)*(1/11)) = 8.8623046875
|
||||||
|
|
||||||
// Avoid needing floating point math
|
// Avoid needing floating point math
|
||||||
health->voltage = (voltage * 8862) / 1000;
|
health->voltage_pkt = (voltage * 8862U) / 1000U;
|
||||||
|
|
||||||
|
// No current sense on panda black
|
||||||
|
if(hw_type != HW_TYPE_BLACK_PANDA){
|
||||||
|
health->current_pkt = adc_get(ADCCHAN_CURRENT);
|
||||||
|
} else {
|
||||||
|
health->current_pkt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
health->current = adc_get(ADCCHAN_CURRENT);
|
|
||||||
int safety_ignition = safety_ignition_hook();
|
int safety_ignition = safety_ignition_hook();
|
||||||
if (safety_ignition < 0) {
|
if (safety_ignition < 0) {
|
||||||
//Use the GPIO pin to determine ignition
|
//Use the GPIO pin to determine ignition
|
||||||
health->started = is_gpio_started();
|
health->started_pkt = (uint8_t)(current_board->check_ignition());
|
||||||
} else {
|
} else {
|
||||||
//Current safety hooks want to determine ignition (ex: GM)
|
//Current safety hooks want to determine ignition (ex: GM)
|
||||||
health->started = safety_ignition;
|
health->started_pkt = safety_ignition;
|
||||||
}
|
}
|
||||||
|
|
||||||
health->controls_allowed = controls_allowed;
|
health->controls_allowed_pkt = controls_allowed;
|
||||||
health->gas_interceptor_detected = gas_interceptor_detected;
|
health->gas_interceptor_detected_pkt = gas_interceptor_detected;
|
||||||
|
health->can_send_errs_pkt = can_send_errs;
|
||||||
// DEPRECATED
|
health->can_fwd_errs_pkt = can_fwd_errs;
|
||||||
health->started_alt = 0;
|
health->gmlan_send_errs_pkt = gmlan_send_errs;
|
||||||
health->started_signal_detected = 0;
|
health->car_harness_status_pkt = car_harness_status;
|
||||||
|
|
||||||
return sizeof(*health);
|
return sizeof(*health);
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) {
|
int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) {
|
||||||
UNUSED(hardwired);
|
UNUSED(hardwired);
|
||||||
CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata;
|
CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata;
|
||||||
int ilen = 0;
|
int ilen = 0;
|
||||||
@@ -150,13 +217,14 @@ int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send on serial, first byte to select the ring
|
// send on serial, first byte to select the ring
|
||||||
void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {
|
void usb_cb_ep2_out(void *usbdata, int len, bool hardwired) {
|
||||||
UNUSED(hardwired);
|
UNUSED(hardwired);
|
||||||
uart_ring *ur = get_ring_by_number(usbdata[0]);
|
uint8_t *usbdata8 = (uint8_t *)usbdata;
|
||||||
|
uart_ring *ur = get_ring_by_number(usbdata8[0]);
|
||||||
if ((len != 0) && (ur != NULL)) {
|
if ((len != 0) && (ur != NULL)) {
|
||||||
if ((usbdata[0] < 2) || safety_tx_lin_hook(usbdata[0]-2, usbdata+1, len-1)) {
|
if ((usbdata8[0] < 2U) || safety_tx_lin_hook(usbdata8[0] - 2U, usbdata8 + 1, len - 1)) {
|
||||||
for (int i = 1; i < len; i++) {
|
for (int i = 1; i < len; i++) {
|
||||||
while (!putc(ur, usbdata[i])) {
|
while (!putc(ur, usbdata8[i])) {
|
||||||
// wait
|
// wait
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,33 +233,29 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send on CAN
|
// send on CAN
|
||||||
void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) {
|
void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) {
|
||||||
UNUSED(hardwired);
|
UNUSED(hardwired);
|
||||||
int dpkt = 0;
|
int dpkt = 0;
|
||||||
for (dpkt = 0; dpkt < len; dpkt += 0x10) {
|
uint32_t *d32 = (uint32_t *)usbdata;
|
||||||
uint32_t *tf = (uint32_t*)(&usbdata[dpkt]);
|
for (dpkt = 0; dpkt < (len / 4); dpkt += 4) {
|
||||||
|
|
||||||
// make a copy
|
|
||||||
CAN_FIFOMailBox_TypeDef to_push;
|
CAN_FIFOMailBox_TypeDef to_push;
|
||||||
to_push.RDHR = tf[3];
|
to_push.RDHR = d32[dpkt + 3];
|
||||||
to_push.RDLR = tf[2];
|
to_push.RDLR = d32[dpkt + 2];
|
||||||
to_push.RDTR = tf[1];
|
to_push.RDTR = d32[dpkt + 1];
|
||||||
to_push.RIR = tf[0];
|
to_push.RIR = d32[dpkt];
|
||||||
|
|
||||||
uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK;
|
uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK;
|
||||||
can_send(&to_push, bus_number);
|
can_send(&to_push, bus_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_enumerated = 0;
|
|
||||||
|
|
||||||
void usb_cb_enumeration_complete() {
|
void usb_cb_enumeration_complete() {
|
||||||
puts("USB enumeration complete\n");
|
puts("USB enumeration complete\n");
|
||||||
is_enumerated = 1;
|
is_enumerated = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) {
|
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) {
|
||||||
int resp_len = 0;
|
unsigned int resp_len = 0;
|
||||||
uart_ring *ur = NULL;
|
uart_ring *ur = NULL;
|
||||||
int i;
|
int i;
|
||||||
switch (setup->b.bRequest) {
|
switch (setup->b.bRequest) {
|
||||||
@@ -203,16 +267,16 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
puts(" err: "); puth(can_err_cnt);
|
puts(" err: "); puth(can_err_cnt);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
break;
|
break;
|
||||||
// **** 0xc1: is grey panda
|
// **** 0xc1: get hardware type
|
||||||
case 0xc1:
|
case 0xc1:
|
||||||
resp[0] = is_grey_panda;
|
resp[0] = hw_type;
|
||||||
resp_len = 1;
|
resp_len = 1;
|
||||||
break;
|
break;
|
||||||
// **** 0xd0: fetch serial number
|
// **** 0xd0: fetch serial number
|
||||||
case 0xd0:
|
case 0xd0:
|
||||||
// addresses are OTP
|
// addresses are OTP
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
memcpy(resp, (void *)0x1fff79c0, 0x10);
|
(void)memcpy(resp, (uint8_t *)0x1fff79c0, 0x10);
|
||||||
resp_len = 0x10;
|
resp_len = 0x10;
|
||||||
} else {
|
} else {
|
||||||
get_provision_chunk(resp);
|
get_provision_chunk(resp);
|
||||||
@@ -248,8 +312,8 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
// **** 0xd6: get version
|
// **** 0xd6: get version
|
||||||
case 0xd6:
|
case 0xd6:
|
||||||
COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN);
|
COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN);
|
||||||
memcpy(resp, gitversion, sizeof(gitversion));
|
(void)memcpy(resp, gitversion, sizeof(gitversion));
|
||||||
resp_len = sizeof(gitversion)-1;
|
resp_len = sizeof(gitversion) - 1U;
|
||||||
break;
|
break;
|
||||||
// **** 0xd8: reset ST
|
// **** 0xd8: reset ST
|
||||||
case 0xd8:
|
case 0xd8:
|
||||||
@@ -257,66 +321,58 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
break;
|
break;
|
||||||
// **** 0xd9: set ESP power
|
// **** 0xd9: set ESP power
|
||||||
case 0xd9:
|
case 0xd9:
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
set_esp_mode(ESP_ENABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
|
||||||
} else if (setup->b.wValue.w == 2) {
|
} else if (setup->b.wValue.w == 2U) {
|
||||||
set_esp_mode(ESP_BOOTMODE);
|
current_board->set_esp_gps_mode(ESP_GPS_BOOTMODE);
|
||||||
} else {
|
} else {
|
||||||
set_esp_mode(ESP_DISABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xda: reset ESP, with optional boot mode
|
// **** 0xda: reset ESP, with optional boot mode
|
||||||
case 0xda:
|
case 0xda:
|
||||||
set_esp_mode(ESP_DISABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
|
||||||
delay(1000000);
|
delay(1000000);
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
set_esp_mode(ESP_BOOTMODE);
|
current_board->set_esp_gps_mode(ESP_GPS_BOOTMODE);
|
||||||
} else {
|
} else {
|
||||||
set_esp_mode(ESP_ENABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
|
||||||
}
|
}
|
||||||
delay(1000000);
|
delay(1000000);
|
||||||
set_esp_mode(ESP_ENABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
|
||||||
break;
|
break;
|
||||||
// **** 0xdb: set GMLAN multiplexing mode
|
// **** 0xdb: set GMLAN (white/grey) or OBD CAN (black) multiplexing mode
|
||||||
case 0xdb:
|
case 0xdb:
|
||||||
if (setup->b.wValue.w == 1) {
|
if(hw_type == HW_TYPE_BLACK_PANDA){
|
||||||
// GMLAN ON
|
if (setup->b.wValue.w == 1U) {
|
||||||
if (setup->b.wIndex.w == 1) {
|
// Enable OBD CAN
|
||||||
can_set_gmlan(1);
|
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
|
||||||
} else if (setup->b.wIndex.w == 2) {
|
} else {
|
||||||
can_set_gmlan(2);
|
// Disable OBD CAN
|
||||||
|
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
can_set_gmlan(-1);
|
if (setup->b.wValue.w == 1U) {
|
||||||
|
// GMLAN ON
|
||||||
|
if (setup->b.wIndex.w == 1U) {
|
||||||
|
can_set_gmlan(1);
|
||||||
|
} else if (setup->b.wIndex.w == 2U) {
|
||||||
|
can_set_gmlan(2);
|
||||||
|
} else {
|
||||||
|
puts("Invalid bus num for GMLAN CAN set\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
can_set_gmlan(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// **** 0xdc: set safety mode
|
// **** 0xdc: set safety mode
|
||||||
case 0xdc:
|
case 0xdc:
|
||||||
// this is the only way to leave silent mode
|
// Blocked over WiFi.
|
||||||
// and it's blocked over WiFi
|
// Allow NOOUTPUT and ELM security mode to be set over wifi.
|
||||||
// Allow ELM security mode to be set over wifi.
|
|
||||||
if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) {
|
if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) {
|
||||||
safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w);
|
set_safety_mode(setup->b.wValue.w, (uint16_t) setup->b.wIndex.w);
|
||||||
if (safety_ignition_hook() != -1) {
|
|
||||||
// if the ignition hook depends on something other than the started GPIO
|
|
||||||
// we have to disable power savings (fix for GM and Tesla)
|
|
||||||
set_power_save_state(POWER_SAVE_STATUS_DISABLED);
|
|
||||||
}
|
|
||||||
#ifndef EON
|
|
||||||
// always LIVE on EON
|
|
||||||
switch (setup->b.wValue.w) {
|
|
||||||
case SAFETY_NOOUTPUT:
|
|
||||||
can_silent = ALL_CAN_SILENT;
|
|
||||||
break;
|
|
||||||
case SAFETY_ELM327:
|
|
||||||
can_silent = ALL_CAN_BUT_MAIN_SILENT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
can_silent = ALL_CAN_LIVE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
can_init_all();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xdd: enable can forwarding
|
// **** 0xdd: enable can forwarding
|
||||||
@@ -326,8 +382,10 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
if ((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w < BUS_MAX) &&
|
if ((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w < BUS_MAX) &&
|
||||||
(setup->b.wValue.w != setup->b.wIndex.w)) { // set forwarding
|
(setup->b.wValue.w != setup->b.wIndex.w)) { // set forwarding
|
||||||
can_set_forwarding(setup->b.wValue.w, setup->b.wIndex.w & CAN_BUS_NUM_MASK);
|
can_set_forwarding(setup->b.wValue.w, setup->b.wIndex.w & CAN_BUS_NUM_MASK);
|
||||||
} else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFF)){ //Clear Forwarding
|
} else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFFU)){ //Clear Forwarding
|
||||||
can_set_forwarding(setup->b.wValue.w, -1);
|
can_set_forwarding(setup->b.wValue.w, -1);
|
||||||
|
} else {
|
||||||
|
puts("Invalid CAN bus forwarding\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xde: set can bitrate
|
// **** 0xde: set can bitrate
|
||||||
@@ -340,7 +398,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
// **** 0xdf: set long controls allowed
|
// **** 0xdf: set long controls allowed
|
||||||
case 0xdf:
|
case 0xdf:
|
||||||
if (hardwired) {
|
if (hardwired) {
|
||||||
long_controls_allowed = setup->b.wValue.w & 1;
|
long_controls_allowed = setup->b.wValue.w & 1U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xe0: uart read
|
// **** 0xe0: uart read
|
||||||
@@ -401,25 +459,25 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
break;
|
break;
|
||||||
// **** 0xe5: set CAN loopback (for testing)
|
// **** 0xe5: set CAN loopback (for testing)
|
||||||
case 0xe5:
|
case 0xe5:
|
||||||
can_loopback = (setup->b.wValue.w > 0);
|
can_loopback = (setup->b.wValue.w > 0U);
|
||||||
can_init_all();
|
can_init_all();
|
||||||
break;
|
break;
|
||||||
// **** 0xe6: set USB power
|
// **** 0xe6: set USB power
|
||||||
case 0xe6:
|
case 0xe6:
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
puts("user setting CDP mode\n");
|
puts("user setting CDP mode\n");
|
||||||
set_usb_power_mode(USB_POWER_CDP);
|
current_board->set_usb_power_mode(USB_POWER_CDP);
|
||||||
} else if (setup->b.wValue.w == 2) {
|
} else if (setup->b.wValue.w == 2U) {
|
||||||
puts("user setting DCP mode\n");
|
puts("user setting DCP mode\n");
|
||||||
set_usb_power_mode(USB_POWER_DCP);
|
current_board->set_usb_power_mode(USB_POWER_DCP);
|
||||||
} else {
|
} else {
|
||||||
puts("user setting CLIENT mode\n");
|
puts("user setting CLIENT mode\n");
|
||||||
set_usb_power_mode(USB_POWER_CLIENT);
|
current_board->set_usb_power_mode(USB_POWER_CLIENT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xf0: do k-line wValue pulse on uart2 for Acura
|
// **** 0xf0: do k-line wValue pulse on uart2 for Acura
|
||||||
case 0xf0:
|
case 0xf0:
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
GPIOC->ODR &= ~(1U << 10);
|
GPIOC->ODR &= ~(1U << 10);
|
||||||
GPIOC->MODER &= ~GPIO_MODER_MODER10_1;
|
GPIOC->MODER &= ~GPIO_MODER_MODER10_1;
|
||||||
GPIOC->MODER |= GPIO_MODER_MODER10_0;
|
GPIOC->MODER |= GPIO_MODER_MODER10_0;
|
||||||
@@ -431,7 +489,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
|
|
||||||
for (i = 0; i < 80; i++) {
|
for (i = 0; i < 80; i++) {
|
||||||
delay(8000);
|
delay(8000);
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
GPIOC->ODR |= (1U << 10);
|
GPIOC->ODR |= (1U << 10);
|
||||||
GPIOC->ODR &= ~(1U << 10);
|
GPIOC->ODR &= ~(1U << 10);
|
||||||
} else {
|
} else {
|
||||||
@@ -440,7 +498,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setup->b.wValue.w == 1) {
|
if (setup->b.wValue.w == 1U) {
|
||||||
GPIOC->MODER &= ~GPIO_MODER_MODER10_0;
|
GPIOC->MODER &= ~GPIO_MODER_MODER10_0;
|
||||||
GPIOC->MODER |= GPIO_MODER_MODER10_1;
|
GPIOC->MODER |= GPIO_MODER_MODER10_1;
|
||||||
} else {
|
} else {
|
||||||
@@ -452,12 +510,14 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
break;
|
break;
|
||||||
// **** 0xf1: Clear CAN ring buffer.
|
// **** 0xf1: Clear CAN ring buffer.
|
||||||
case 0xf1:
|
case 0xf1:
|
||||||
if (setup->b.wValue.w == 0xFFFF) {
|
if (setup->b.wValue.w == 0xFFFFU) {
|
||||||
puts("Clearing CAN Rx queue\n");
|
puts("Clearing CAN Rx queue\n");
|
||||||
can_clear(&can_rx_q);
|
can_clear(&can_rx_q);
|
||||||
} else if (setup->b.wValue.w < BUS_MAX) {
|
} else if (setup->b.wValue.w < BUS_MAX) {
|
||||||
puts("Clearing CAN Tx queue\n");
|
puts("Clearing CAN Tx queue\n");
|
||||||
can_clear(can_queues[setup->b.wValue.w]);
|
can_clear(can_queues[setup->b.wValue.w]);
|
||||||
|
} else {
|
||||||
|
puts("Clearing CAN CAN ring buffer failed: wrong bus number\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// **** 0xf2: Clear UART ring buffer.
|
// **** 0xf2: Clear UART ring buffer.
|
||||||
@@ -470,6 +530,12 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// **** 0xf3: Heartbeat. Resets heartbeat counter.
|
||||||
|
case 0xf3:
|
||||||
|
{
|
||||||
|
heartbeat_counter = 0U;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
puts("NO HANDLER ");
|
puts("NO HANDLER ");
|
||||||
puth(setup->b.bRequest);
|
puth(setup->b.bRequest);
|
||||||
@@ -479,6 +545,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
return resp_len;
|
return resp_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef EON
|
||||||
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
||||||
// data[0] = endpoint
|
// data[0] = endpoint
|
||||||
// data[2] = length
|
// data[2] = length
|
||||||
@@ -508,111 +575,70 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
|||||||
}
|
}
|
||||||
return resp_len;
|
return resp_len;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ***************************** main code *****************************
|
// ***************************** main code *****************************
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
void __initialize_hardware_early(void) {
|
void __initialize_hardware_early(void) {
|
||||||
early();
|
early();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__ ((noinline)) enable_fpu(void) {
|
void __attribute__ ((noinline)) enable_fpu(void) {
|
||||||
// enable the FPU
|
// enable the FPU
|
||||||
SCB->CPACR |= ((3UL << (10U * 2)) | (3UL << (11U * 2)));
|
SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U)));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t tcnt = 0;
|
uint64_t tcnt = 0;
|
||||||
uint64_t marker = 0;
|
|
||||||
|
// go into NOOUTPUT when the EON does not send a heartbeat for this amount of seconds.
|
||||||
|
#define EON_HEARTBEAT_THRESHOLD_IGNITION_ON 5U
|
||||||
|
#define EON_HEARTBEAT_THRESHOLD_IGNITION_OFF 2U
|
||||||
|
|
||||||
// called once per second
|
// called once per second
|
||||||
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
void TIM3_IRQHandler(void) {
|
void TIM3_IRQHandler(void) {
|
||||||
#define CURRENT_THRESHOLD 0xF00
|
|
||||||
#define CLICKS 5 // 5 seconds to switch modes
|
|
||||||
|
|
||||||
if (TIM3->SR != 0) {
|
if (TIM3->SR != 0) {
|
||||||
can_live = pending_can_live;
|
can_live = pending_can_live;
|
||||||
|
|
||||||
|
current_board->usb_power_mode_tick(tcnt);
|
||||||
|
|
||||||
//puth(usart1_dma); puts(" "); puth(DMA2_Stream5->M0AR); puts(" "); puth(DMA2_Stream5->NDTR); puts("\n");
|
//puth(usart1_dma); puts(" "); puth(DMA2_Stream5->M0AR); puts(" "); puth(DMA2_Stream5->NDTR); puts("\n");
|
||||||
|
|
||||||
uint32_t current = adc_get(ADCCHAN_CURRENT);
|
|
||||||
|
|
||||||
switch (usb_power_mode) {
|
|
||||||
case USB_POWER_CLIENT:
|
|
||||||
if ((tcnt-marker) >= CLICKS) {
|
|
||||||
if (!is_enumerated) {
|
|
||||||
puts("USBP: didn't enumerate, switching to CDP mode\n");
|
|
||||||
// switch to CDP
|
|
||||||
set_usb_power_mode(USB_POWER_CDP);
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// keep resetting the timer if it's enumerated
|
|
||||||
if (is_enumerated) {
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case USB_POWER_CDP:
|
|
||||||
// On the EON, if we get into CDP mode we stay here. No need to go to DCP.
|
|
||||||
#ifndef EON
|
|
||||||
// been CLICKS clicks since we switched to CDP
|
|
||||||
if ((tcnt-marker) >= CLICKS) {
|
|
||||||
// measure current draw, if positive and no enumeration, switch to DCP
|
|
||||||
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
|
|
||||||
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
|
|
||||||
set_usb_power_mode(USB_POWER_DCP);
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// keep resetting the timer if there's no current draw in CDP
|
|
||||||
if (current >= CURRENT_THRESHOLD) {
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case USB_POWER_DCP:
|
|
||||||
// been at least CLICKS clicks since we switched to DCP
|
|
||||||
if ((tcnt-marker) >= CLICKS) {
|
|
||||||
// if no current draw, switch back to CDP
|
|
||||||
if (current >= CURRENT_THRESHOLD) {
|
|
||||||
puts("USBP: no current draw, switching back to CDP mode\n");
|
|
||||||
set_usb_power_mode(USB_POWER_CDP);
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// keep resetting the timer if there's current draw in DCP
|
|
||||||
if (current < CURRENT_THRESHOLD) {
|
|
||||||
marker = tcnt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
puts("USB power mode invalid\n"); // set_usb_power_mode prevents assigning invalid values
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~0x9a = 500 ma
|
|
||||||
/*puth(current);
|
|
||||||
puts("\n");*/
|
|
||||||
|
|
||||||
// reset this every 16th pass
|
// reset this every 16th pass
|
||||||
if ((tcnt&0xF) == 0) {
|
if ((tcnt & 0xFU) == 0U) {
|
||||||
pending_can_live = 0;
|
pending_can_live = 0;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("** blink ");
|
//TODO: re-enable
|
||||||
puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
|
//puts("** blink ");
|
||||||
puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
|
//puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
|
||||||
puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
|
//puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
|
||||||
|
//puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set green LED to be controls allowed
|
// set green LED to be controls allowed
|
||||||
set_led(LED_GREEN, controls_allowed);
|
current_board->set_led(LED_GREEN, controls_allowed);
|
||||||
|
|
||||||
// turn off the blue LED, turned on by CAN
|
// turn off the blue LED, turned on by CAN
|
||||||
// unless we are in power saving mode
|
// unless we are in power saving mode
|
||||||
set_led(LED_BLUE, (tcnt & 1) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
|
current_board->set_led(LED_BLUE, (tcnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
|
||||||
|
|
||||||
|
// increase heartbeat counter and cap it at the uint32 limit
|
||||||
|
if (heartbeat_counter < __UINT32_MAX__) {
|
||||||
|
heartbeat_counter += 1U;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check heartbeat counter if we are running EON code. If the heartbeat has been gone for a while, go to NOOUTPUT safety mode.
|
||||||
|
#ifdef EON
|
||||||
|
if (heartbeat_counter >= (current_board->check_ignition() ? EON_HEARTBEAT_THRESHOLD_IGNITION_ON : EON_HEARTBEAT_THRESHOLD_IGNITION_OFF)) {
|
||||||
|
puts("EON hasn't sent a heartbeat for 0x"); puth(heartbeat_counter); puts(" seconds. Safety is set to NOOUTPUT mode.\n");
|
||||||
|
set_safety_mode(SAFETY_NOOUTPUT, 0U);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// on to the next one
|
// on to the next one
|
||||||
tcnt += 1;
|
tcnt += 1U;
|
||||||
}
|
}
|
||||||
TIM3->SR = 0;
|
TIM3->SR = 0;
|
||||||
}
|
}
|
||||||
@@ -623,26 +649,27 @@ int main(void) {
|
|||||||
|
|
||||||
// init early devices
|
// init early devices
|
||||||
clock_init();
|
clock_init();
|
||||||
periph_init();
|
peripherals_init();
|
||||||
detect();
|
detect_configuration();
|
||||||
|
detect_board_type();
|
||||||
|
adc_init();
|
||||||
|
|
||||||
// print hello
|
// print hello
|
||||||
puts("\n\n\n************************ MAIN START ************************\n");
|
puts("\n\n\n************************ MAIN START ************************\n");
|
||||||
|
|
||||||
// detect the revision and init the GPIOs
|
// check for non-supported board types
|
||||||
puts("config:\n");
|
if(hw_type == HW_TYPE_UNKNOWN){
|
||||||
puts((revision == PANDA_REV_C) ? " panda rev c\n" : " panda rev a or b\n");
|
puts("Unsupported board type\n");
|
||||||
puts(has_external_debug_serial ? " real serial\n" : " USB serial\n");
|
while (1) { /* hang */ }
|
||||||
puts(is_giant_panda ? " GIANTpanda detected\n" : " not GIANTpanda\n");
|
|
||||||
puts(is_grey_panda ? " gray panda detected!\n" : " white panda\n");
|
|
||||||
puts(is_entering_bootmode ? " ESP wants bootmode\n" : " no bootmode\n");
|
|
||||||
|
|
||||||
// non rev c panda are no longer supported
|
|
||||||
while (revision != PANDA_REV_C) {
|
|
||||||
// hang
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_init();
|
puts("Config:\n");
|
||||||
|
puts(" Board type: "); puts(current_board->board_type); puts("\n");
|
||||||
|
puts(has_external_debug_serial ? " Real serial\n" : " USB serial\n");
|
||||||
|
puts(is_entering_bootmode ? " ESP wants bootmode\n" : " No bootmode\n");
|
||||||
|
|
||||||
|
// init board
|
||||||
|
current_board->init();
|
||||||
|
|
||||||
// panda has an FPU, let's use it!
|
// panda has an FPU, let's use it!
|
||||||
enable_fpu();
|
enable_fpu();
|
||||||
@@ -654,18 +681,21 @@ int main(void) {
|
|||||||
uart_init(USART2, 115200);
|
uart_init(USART2, 115200);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_grey_panda) {
|
if (board_has_gps()) {
|
||||||
uart_init(USART1, 9600);
|
uart_init(USART1, 9600);
|
||||||
} else {
|
} else {
|
||||||
// enable ESP uart
|
// enable ESP uart
|
||||||
uart_init(USART1, 115200);
|
uart_init(USART1, 115200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable LIN
|
// there is no LIN on panda black
|
||||||
uart_init(UART5, 10400);
|
if(hw_type != HW_TYPE_BLACK_PANDA){
|
||||||
UART5->CR2 |= USART_CR2_LINEN;
|
// enable LIN
|
||||||
uart_init(USART3, 10400);
|
uart_init(UART5, 10400);
|
||||||
USART3->CR2 |= USART_CR2_LINEN;
|
UART5->CR2 |= USART_CR2_LINEN;
|
||||||
|
uart_init(USART3, 10400);
|
||||||
|
USART3->CR2 |= USART_CR2_LINEN;
|
||||||
|
}
|
||||||
|
|
||||||
// init microsecond system timer
|
// init microsecond system timer
|
||||||
// increments 1000000 times per second
|
// increments 1000000 times per second
|
||||||
@@ -675,37 +705,36 @@ int main(void) {
|
|||||||
TIM2->EGR = TIM_EGR_UG;
|
TIM2->EGR = TIM_EGR_UG;
|
||||||
// use TIM2->CNT to read
|
// use TIM2->CNT to read
|
||||||
|
|
||||||
// enable USB
|
|
||||||
usb_init();
|
|
||||||
|
|
||||||
// default to silent mode to prevent issues with Ford
|
// default to silent mode to prevent issues with Ford
|
||||||
// hardcode a specific safety mode if you want to force the panda to be in a specific mode
|
// hardcode a specific safety mode if you want to force the panda to be in a specific mode
|
||||||
safety_set_mode(SAFETY_NOOUTPUT, 0);
|
int err = safety_set_mode(SAFETY_NOOUTPUT, 0);
|
||||||
#ifdef EON
|
if (err == -1) {
|
||||||
// if we're on an EON, it's fine for CAN to be live for fingerprinting
|
puts("Failed to set safety mode\n");
|
||||||
can_silent = ALL_CAN_LIVE;
|
while (true) {
|
||||||
#else
|
// if SAFETY_NOOUTPUT isn't succesfully set, we can't continue
|
||||||
|
}
|
||||||
|
}
|
||||||
can_silent = ALL_CAN_SILENT;
|
can_silent = ALL_CAN_SILENT;
|
||||||
#endif
|
|
||||||
can_init_all();
|
can_init_all();
|
||||||
|
|
||||||
adc_init();
|
|
||||||
|
|
||||||
#ifndef EON
|
#ifndef EON
|
||||||
spi_init();
|
spi_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EON
|
#ifdef EON
|
||||||
// have to save power
|
// have to save power
|
||||||
if (!is_grey_panda) {
|
if (hw_type == HW_TYPE_WHITE_PANDA) {
|
||||||
set_esp_mode(ESP_DISABLED);
|
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
|
||||||
}
|
}
|
||||||
// only enter power save after the first cycle
|
// only enter power save after the first cycle
|
||||||
/*if (is_gpio_started()) {
|
/*if (current_board->check_ignition()) {
|
||||||
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
|
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
|
||||||
}*/
|
}*/
|
||||||
// interrupt on started line
|
|
||||||
started_interrupt_init();
|
if (hw_type != HW_TYPE_BLACK_PANDA) {
|
||||||
|
// interrupt on started line
|
||||||
|
started_interrupt_init();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 48mhz / 65536 ~= 732 / 732 = 1
|
// 48mhz / 65536 ~= 732 / 732 = 1
|
||||||
@@ -715,6 +744,8 @@ int main(void) {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("DEBUG ENABLED\n");
|
puts("DEBUG ENABLED\n");
|
||||||
#endif
|
#endif
|
||||||
|
// enable USB (right before interrupts or enum can fail!)
|
||||||
|
usb_init();
|
||||||
|
|
||||||
puts("**** INTERRUPTS ON ****\n");
|
puts("**** INTERRUPTS ON ****\n");
|
||||||
enable_interrupts();
|
enable_interrupts();
|
||||||
@@ -730,9 +761,9 @@ int main(void) {
|
|||||||
for (int div_mode_loop = 0; div_mode_loop < div_mode; div_mode_loop++) {
|
for (int div_mode_loop = 0; div_mode_loop < div_mode; div_mode_loop++) {
|
||||||
for (int fade = 0; fade < 1024; fade += 8) {
|
for (int fade = 0; fade < 1024; fade += 8) {
|
||||||
for (int i = 0; i < (128/div_mode); i++) {
|
for (int i = 0; i < (128/div_mode); i++) {
|
||||||
set_led(LED_RED, 1);
|
current_board->set_led(LED_RED, 1);
|
||||||
if (fade < 512) { delay(fade); } else { delay(1024-fade); }
|
if (fade < 512) { delay(fade); } else { delay(1024-fade); }
|
||||||
set_led(LED_RED, 0);
|
current_board->set_led(LED_RED, 0);
|
||||||
if (fade < 512) { delay(512-fade); } else { delay(fade-512); }
|
if (fade < 512) { delay(512-fade); } else { delay(fade-512); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -744,4 +775,3 @@ int main(void) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// ******************** Prototypes ********************
|
||||||
|
void puts(const char *a);
|
||||||
|
void puth(unsigned int i);
|
||||||
|
void puth2(unsigned int i);
|
||||||
|
typedef struct board board;
|
||||||
|
typedef struct harness_configuration harness_configuration;
|
||||||
|
void can_flip_buses(uint8_t bus1, uint8_t bus2);
|
||||||
|
void can_set_obd(uint8_t harness_orientation, bool obd);
|
||||||
|
|
||||||
|
// ********************* Globals **********************
|
||||||
|
uint8_t hw_type = 0;
|
||||||
|
const board *current_board;
|
||||||
|
bool is_enumerated = 0;
|
||||||
|
uint32_t heartbeat_counter = 0;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
# :set noet
|
# :set noet
|
||||||
PROJ_NAME = comma
|
PROJ_NAME = comma
|
||||||
|
|
||||||
CFLAGS = -O2 -Wall -std=gnu11 -DPEDAL
|
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -Werror -std=gnu11 -DPEDAL
|
||||||
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
|
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
|
||||||
CFLAGS += -msoft-float -DSTM32F2 -DSTM32F205xx
|
CFLAGS += -msoft-float -DSTM32F2 -DSTM32F205xx
|
||||||
CFLAGS += -I ../inc -I ../ -I ../../ -nostdlib
|
CFLAGS += -I ../inc -I ../ -I ../../ -nostdlib -fno-builtin
|
||||||
CFLAGS += -T../stm32_flash.ld
|
CFLAGS += -T../stm32_flash.ld
|
||||||
|
|
||||||
STARTUP_FILE = startup_stm32f205xx
|
STARTUP_FILE = startup_stm32f205xx
|
||||||
|
|||||||
+108
-61
@@ -1,14 +1,20 @@
|
|||||||
|
// ********************* Includes *********************
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
#include "main_declarations.h"
|
||||||
|
|
||||||
#include "drivers/llcan.h"
|
#include "drivers/llcan.h"
|
||||||
#include "drivers/llgpio.h"
|
#include "drivers/llgpio.h"
|
||||||
#include "drivers/clock.h"
|
|
||||||
#include "drivers/adc.h"
|
#include "drivers/adc.h"
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
|
#include "drivers/clock.h"
|
||||||
#include "drivers/dac.h"
|
#include "drivers/dac.h"
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "libc.h"
|
|
||||||
|
|
||||||
#define CAN CAN1
|
#define CAN CAN1
|
||||||
|
|
||||||
@@ -19,14 +25,22 @@
|
|||||||
#include "drivers/usb.h"
|
#include "drivers/usb.h"
|
||||||
#else
|
#else
|
||||||
// no serial either
|
// no serial either
|
||||||
void puts(const char *a) {}
|
void puts(const char *a) {
|
||||||
void puth(unsigned int i) {}
|
UNUSED(a);
|
||||||
|
}
|
||||||
|
void puth(unsigned int i) {
|
||||||
|
UNUSED(i);
|
||||||
|
}
|
||||||
|
void puth2(unsigned int i) {
|
||||||
|
UNUSED(i);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
|
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
|
||||||
uint32_t enter_bootloader_mode;
|
uint32_t enter_bootloader_mode;
|
||||||
|
|
||||||
void __initialize_hardware_early() {
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void __initialize_hardware_early(void) {
|
||||||
early();
|
early();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,31 +50,54 @@ void __initialize_hardware_early() {
|
|||||||
|
|
||||||
void debug_ring_callback(uart_ring *ring) {
|
void debug_ring_callback(uart_ring *ring) {
|
||||||
char rcv;
|
char rcv;
|
||||||
while (getc(ring, &rcv)) {
|
while (getc(ring, &rcv) != 0) {
|
||||||
putc(ring, rcv);
|
(void)putc(ring, rcv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { return 0; }
|
int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) {
|
||||||
void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {}
|
UNUSED(usbdata);
|
||||||
void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) {}
|
UNUSED(len);
|
||||||
void usb_cb_enumeration_complete() {}
|
UNUSED(hardwired);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {
|
||||||
|
UNUSED(usbdata);
|
||||||
|
UNUSED(len);
|
||||||
|
UNUSED(hardwired);
|
||||||
|
}
|
||||||
|
void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) {
|
||||||
|
UNUSED(usbdata);
|
||||||
|
UNUSED(len);
|
||||||
|
UNUSED(hardwired);
|
||||||
|
}
|
||||||
|
void usb_cb_enumeration_complete(void) {}
|
||||||
|
|
||||||
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) {
|
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) {
|
||||||
int resp_len = 0;
|
UNUSED(hardwired);
|
||||||
|
unsigned int resp_len = 0;
|
||||||
uart_ring *ur = NULL;
|
uart_ring *ur = NULL;
|
||||||
switch (setup->b.bRequest) {
|
switch (setup->b.bRequest) {
|
||||||
// **** 0xe0: uart read
|
// **** 0xe0: uart read
|
||||||
case 0xe0:
|
case 0xe0:
|
||||||
ur = get_ring_by_number(setup->b.wValue.w);
|
ur = get_ring_by_number(setup->b.wValue.w);
|
||||||
if (!ur) break;
|
if (!ur) {
|
||||||
if (ur == &esp_ring) uart_dma_drain();
|
break;
|
||||||
|
}
|
||||||
|
if (ur == &esp_ring) {
|
||||||
|
uart_dma_drain();
|
||||||
|
}
|
||||||
// read
|
// read
|
||||||
while ((resp_len < MIN(setup->b.wLength.w, MAX_RESP_LEN)) &&
|
while ((resp_len < MIN(setup->b.wLength.w, MAX_RESP_LEN)) &&
|
||||||
getc(ur, (char*)&resp[resp_len])) {
|
getc(ur, (char*)&resp[resp_len])) {
|
||||||
++resp_len;
|
++resp_len;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
puts("NO HANDLER ");
|
||||||
|
puth(setup->b.bRequest);
|
||||||
|
puts("\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return resp_len;
|
return resp_len;
|
||||||
}
|
}
|
||||||
@@ -76,7 +113,7 @@ uint8_t pedal_checksum(uint8_t *dat, int len) {
|
|||||||
for (i = len - 1; i >= 0; i--) {
|
for (i = len - 1; i >= 0; i--) {
|
||||||
crc ^= dat[i];
|
crc ^= dat[i];
|
||||||
for (j = 0; j < 8; j++) {
|
for (j = 0; j < 8; j++) {
|
||||||
if ((crc & 0x80) != 0) {
|
if ((crc & 0x80U) != 0U) {
|
||||||
crc = (uint8_t)((crc << 1) ^ poly);
|
crc = (uint8_t)((crc << 1) ^ poly);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -91,11 +128,12 @@ uint8_t pedal_checksum(uint8_t *dat, int len) {
|
|||||||
|
|
||||||
// addresses to be used on CAN
|
// addresses to be used on CAN
|
||||||
#define CAN_GAS_INPUT 0x200
|
#define CAN_GAS_INPUT 0x200
|
||||||
#define CAN_GAS_OUTPUT 0x201
|
#define CAN_GAS_OUTPUT 0x201U
|
||||||
#define CAN_GAS_SIZE 6
|
#define CAN_GAS_SIZE 6
|
||||||
#define COUNTER_CYCLE 0xF
|
#define COUNTER_CYCLE 0xFU
|
||||||
|
|
||||||
void CAN1_TX_IRQHandler() {
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void CAN1_TX_IRQHandler(void) {
|
||||||
// clear interrupt
|
// clear interrupt
|
||||||
CAN->TSR |= CAN_TSR_RQCP0;
|
CAN->TSR |= CAN_TSR_RQCP0;
|
||||||
}
|
}
|
||||||
@@ -104,54 +142,54 @@ void CAN1_TX_IRQHandler() {
|
|||||||
uint16_t gas_set_0 = 0;
|
uint16_t gas_set_0 = 0;
|
||||||
uint16_t gas_set_1 = 0;
|
uint16_t gas_set_1 = 0;
|
||||||
|
|
||||||
#define MAX_TIMEOUT 10
|
#define MAX_TIMEOUT 10U
|
||||||
uint32_t timeout = 0;
|
uint32_t timeout = 0;
|
||||||
uint32_t current_index = 0;
|
uint32_t current_index = 0;
|
||||||
|
|
||||||
#define NO_FAULT 0
|
#define NO_FAULT 0U
|
||||||
#define FAULT_BAD_CHECKSUM 1
|
#define FAULT_BAD_CHECKSUM 1U
|
||||||
#define FAULT_SEND 2
|
#define FAULT_SEND 2U
|
||||||
#define FAULT_SCE 3
|
#define FAULT_SCE 3U
|
||||||
#define FAULT_STARTUP 4
|
#define FAULT_STARTUP 4U
|
||||||
#define FAULT_TIMEOUT 5
|
#define FAULT_TIMEOUT 5U
|
||||||
#define FAULT_INVALID 6
|
#define FAULT_INVALID 6U
|
||||||
uint8_t state = FAULT_STARTUP;
|
uint8_t state = FAULT_STARTUP;
|
||||||
|
|
||||||
void CAN1_RX0_IRQHandler() {
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
while (CAN->RF0R & CAN_RF0R_FMP0) {
|
void CAN1_RX0_IRQHandler(void) {
|
||||||
|
while ((CAN->RF0R & CAN_RF0R_FMP0) != 0) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("CAN RX\n");
|
puts("CAN RX\n");
|
||||||
#endif
|
#endif
|
||||||
uint32_t address = CAN->sFIFOMailBox[0].RIR>>21;
|
int address = CAN->sFIFOMailBox[0].RIR >> 21;
|
||||||
if (address == CAN_GAS_INPUT) {
|
if (address == CAN_GAS_INPUT) {
|
||||||
// softloader entry
|
// softloader entry
|
||||||
if (CAN->sFIFOMailBox[0].RDLR == 0xdeadface) {
|
if (GET_BYTES_04(&CAN->sFIFOMailBox[0]) == 0xdeadface) {
|
||||||
if (CAN->sFIFOMailBox[0].RDHR == 0x0ab00b1e) {
|
if (GET_BYTES_48(&CAN->sFIFOMailBox[0]) == 0x0ab00b1e) {
|
||||||
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
|
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
} else if (CAN->sFIFOMailBox[0].RDHR == 0x02b00b1e) {
|
} else if (GET_BYTES_48(&CAN->sFIFOMailBox[0]) == 0x02b00b1e) {
|
||||||
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
|
} else {
|
||||||
|
puts("Failed entering Softloader or Bootloader\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal packet
|
// normal packet
|
||||||
uint8_t dat[8];
|
uint8_t dat[8];
|
||||||
uint8_t *rdlr = (uint8_t *)&CAN->sFIFOMailBox[0].RDLR;
|
for (int i=0; i<8; i++) {
|
||||||
uint8_t *rdhr = (uint8_t *)&CAN->sFIFOMailBox[0].RDHR;
|
dat[i] = GET_BYTE(&CAN->sFIFOMailBox[0], i);
|
||||||
for (int i=0; i<4; i++) {
|
|
||||||
dat[i] = rdlr[i];
|
|
||||||
dat[i+4] = rdhr[i];
|
|
||||||
}
|
}
|
||||||
uint16_t value_0 = (dat[0] << 8) | dat[1];
|
uint16_t value_0 = (dat[0] << 8) | dat[1];
|
||||||
uint16_t value_1 = (dat[2] << 8) | dat[3];
|
uint16_t value_1 = (dat[2] << 8) | dat[3];
|
||||||
uint8_t enable = (dat[4] >> 7) & 1;
|
bool enable = ((dat[4] >> 7) & 1U) != 0U;
|
||||||
uint8_t index = dat[4] & COUNTER_CYCLE;
|
uint8_t index = dat[4] & COUNTER_CYCLE;
|
||||||
if (pedal_checksum(dat, CAN_GAS_SIZE - 1) == dat[5]) {
|
if (pedal_checksum(dat, CAN_GAS_SIZE - 1) == dat[5]) {
|
||||||
if (((current_index + 1) & COUNTER_CYCLE) == index) {
|
if (((current_index + 1U) & COUNTER_CYCLE) == index) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("setting gas ");
|
puts("setting gas ");
|
||||||
puth(value);
|
puth(value_0);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
#endif
|
#endif
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@@ -159,12 +197,13 @@ void CAN1_RX0_IRQHandler() {
|
|||||||
gas_set_1 = value_1;
|
gas_set_1 = value_1;
|
||||||
} else {
|
} else {
|
||||||
// clear the fault state if values are 0
|
// clear the fault state if values are 0
|
||||||
if (value_0 == 0 && value_1 == 0) {
|
if ((value_0 == 0U) && (value_1 == 0U)) {
|
||||||
state = NO_FAULT;
|
state = NO_FAULT;
|
||||||
} else {
|
} else {
|
||||||
state = FAULT_INVALID;
|
state = FAULT_INVALID;
|
||||||
}
|
}
|
||||||
gas_set_0 = gas_set_1 = 0;
|
gas_set_0 = 0;
|
||||||
|
gas_set_1 = 0;
|
||||||
}
|
}
|
||||||
// clear the timeout
|
// clear the timeout
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
@@ -180,17 +219,20 @@ void CAN1_RX0_IRQHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAN1_SCE_IRQHandler() {
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void CAN1_SCE_IRQHandler(void) {
|
||||||
state = FAULT_SCE;
|
state = FAULT_SCE;
|
||||||
llcan_clear_send(CAN);
|
llcan_clear_send(CAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pdl0 = 0, pdl1 = 0;
|
uint32_t pdl0 = 0;
|
||||||
int pkt_idx = 0;
|
uint32_t pdl1 = 0;
|
||||||
|
unsigned int pkt_idx = 0;
|
||||||
|
|
||||||
int led_value = 0;
|
int led_value = 0;
|
||||||
|
|
||||||
void TIM3_IRQHandler() {
|
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
|
||||||
|
void TIM3_IRQHandler(void) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puth(TIM3->CNT);
|
puth(TIM3->CNT);
|
||||||
puts(" ");
|
puts(" ");
|
||||||
@@ -203,16 +245,16 @@ void TIM3_IRQHandler() {
|
|||||||
// check timer for sending the user pedal and clearing the CAN
|
// check timer for sending the user pedal and clearing the CAN
|
||||||
if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) {
|
if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) {
|
||||||
uint8_t dat[8];
|
uint8_t dat[8];
|
||||||
dat[0] = (pdl0>>8) & 0xFF;
|
dat[0] = (pdl0 >> 8) & 0xFFU;
|
||||||
dat[1] = (pdl0>>0) & 0xFF;
|
dat[1] = (pdl0 >> 0) & 0xFFU;
|
||||||
dat[2] = (pdl1>>8) & 0xFF;
|
dat[2] = (pdl1 >> 8) & 0xFFU;
|
||||||
dat[3] = (pdl1>>0) & 0xFF;
|
dat[3] = (pdl1 >> 0) & 0xFFU;
|
||||||
dat[4] = (state & 0xF) << 4 | pkt_idx;
|
dat[4] = ((state & 0xFU) << 4) | pkt_idx;
|
||||||
dat[5] = pedal_checksum(dat, CAN_GAS_SIZE - 1);
|
dat[5] = pedal_checksum(dat, CAN_GAS_SIZE - 1);
|
||||||
CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1]<<8) | (dat[2]<<16) | (dat[3]<<24);
|
CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1] << 8) | (dat[2] << 16) | (dat[3] << 24);
|
||||||
CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5]<<8);
|
CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5] << 8);
|
||||||
CAN->sTxMailBox[0].TDTR = 6; // len of packet is 5
|
CAN->sTxMailBox[0].TDTR = 6; // len of packet is 5
|
||||||
CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1;
|
CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1U;
|
||||||
++pkt_idx;
|
++pkt_idx;
|
||||||
pkt_idx &= COUNTER_CYCLE;
|
pkt_idx &= COUNTER_CYCLE;
|
||||||
} else {
|
} else {
|
||||||
@@ -224,7 +266,7 @@ void TIM3_IRQHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blink the LED
|
// blink the LED
|
||||||
set_led(LED_GREEN, led_value);
|
current_board->set_led(LED_GREEN, led_value);
|
||||||
led_value = !led_value;
|
led_value = !led_value;
|
||||||
|
|
||||||
TIM3->SR = 0;
|
TIM3->SR = 0;
|
||||||
@@ -233,13 +275,13 @@ void TIM3_IRQHandler() {
|
|||||||
if (timeout == MAX_TIMEOUT) {
|
if (timeout == MAX_TIMEOUT) {
|
||||||
state = FAULT_TIMEOUT;
|
state = FAULT_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
timeout += 1;
|
timeout += 1U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************** main code *****************************
|
// ***************************** main code *****************************
|
||||||
|
|
||||||
void pedal() {
|
void pedal(void) {
|
||||||
// read/write
|
// read/write
|
||||||
pdl0 = adc_get(ADCCHAN_ACCEL0);
|
pdl0 = adc_get(ADCCHAN_ACCEL0);
|
||||||
pdl1 = adc_get(ADCCHAN_ACCEL1);
|
pdl1 = adc_get(ADCCHAN_ACCEL1);
|
||||||
@@ -256,13 +298,14 @@ void pedal() {
|
|||||||
watchdog_feed();
|
watchdog_feed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(void) {
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
||||||
// init devices
|
// init devices
|
||||||
clock_init();
|
clock_init();
|
||||||
periph_init();
|
peripherals_init();
|
||||||
gpio_init();
|
detect_configuration();
|
||||||
|
detect_board_type();
|
||||||
|
|
||||||
#ifdef PEDAL_USB
|
#ifdef PEDAL_USB
|
||||||
// enable USB
|
// enable USB
|
||||||
@@ -274,7 +317,11 @@ int main() {
|
|||||||
adc_init();
|
adc_init();
|
||||||
|
|
||||||
// init can
|
// init can
|
||||||
llcan_set_speed(CAN1, 5000, false, false);
|
bool llcan_speed_set = llcan_set_speed(CAN1, 5000, false, false);
|
||||||
|
if (!llcan_speed_set) {
|
||||||
|
puts("Failed to set llcan speed");
|
||||||
|
}
|
||||||
|
|
||||||
llcan_init(CAN1);
|
llcan_init(CAN1);
|
||||||
|
|
||||||
// 48mhz / 65536 ~= 732
|
// 48mhz / 65536 ~= 732
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// ******************** Prototypes ********************
|
||||||
|
void puts(const char *a);
|
||||||
|
void puth(unsigned int i);
|
||||||
|
void puth2(unsigned int i);
|
||||||
|
typedef struct board board;
|
||||||
|
typedef struct harness_configuration harness_configuration;
|
||||||
|
|
||||||
|
// ********************* Globals **********************
|
||||||
|
uint8_t hw_type = 0;
|
||||||
|
const board *current_board;
|
||||||
|
bool is_enumerated = 0;
|
||||||
+14
-14
@@ -10,33 +10,33 @@ void set_power_save_state(int state) {
|
|||||||
bool enable = false;
|
bool enable = false;
|
||||||
if (state == POWER_SAVE_STATUS_ENABLED) {
|
if (state == POWER_SAVE_STATUS_ENABLED) {
|
||||||
puts("enable power savings\n");
|
puts("enable power savings\n");
|
||||||
if (is_grey_panda) {
|
if (board_has_gps()) {
|
||||||
char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
|
char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
|
||||||
uart_ring *ur = get_ring_by_number(1);
|
uart_ring *ur = get_ring_by_number(1);
|
||||||
for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
|
for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
puts("disable power savings\n");
|
puts("disable power savings\n");
|
||||||
if (is_grey_panda) {
|
if (board_has_gps()) {
|
||||||
char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
|
char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
|
||||||
uart_ring *ur = get_ring_by_number(1);
|
uart_ring *ur = get_ring_by_number(1);
|
||||||
for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
|
for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
|
||||||
}
|
}
|
||||||
enable = true;
|
enable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn on can
|
// Switch CAN transcievers
|
||||||
set_can_enable(CAN1, enable);
|
current_board->enable_can_transcievers(enable);
|
||||||
set_can_enable(CAN2, enable);
|
|
||||||
set_can_enable(CAN3, enable);
|
|
||||||
|
|
||||||
// turn on GMLAN
|
if(hw_type != HW_TYPE_BLACK_PANDA){
|
||||||
set_gpio_output(GPIOB, 14, enable);
|
// turn on GMLAN
|
||||||
set_gpio_output(GPIOB, 15, enable);
|
set_gpio_output(GPIOB, 14, enable);
|
||||||
|
set_gpio_output(GPIOB, 15, enable);
|
||||||
|
|
||||||
// turn on LIN
|
// turn on LIN
|
||||||
set_gpio_output(GPIOB, 7, enable);
|
set_gpio_output(GPIOB, 7, enable);
|
||||||
set_gpio_output(GPIOA, 14, enable);
|
set_gpio_output(GPIOA, 14, enable);
|
||||||
|
}
|
||||||
|
|
||||||
power_save_status = state;
|
power_save_status = state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
// SHA1 checksum = 0x1C - 0x20
|
// SHA1 checksum = 0x1C - 0x20
|
||||||
|
|
||||||
void get_provision_chunk(uint8_t *resp) {
|
void get_provision_chunk(uint8_t *resp) {
|
||||||
memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN);
|
(void)memcpy(resp, (uint8_t *)0x1fff79e0, PROVISION_CHUNK_LEN);
|
||||||
if (memcmp(resp, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x20) == 0) {
|
if (memcmp(resp, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x20) == 0) {
|
||||||
memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20);
|
(void)memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-15
@@ -44,21 +44,21 @@ typedef struct {
|
|||||||
const safety_hooks *hooks;
|
const safety_hooks *hooks;
|
||||||
} safety_hook_config;
|
} safety_hook_config;
|
||||||
|
|
||||||
#define SAFETY_NOOUTPUT 0
|
#define SAFETY_NOOUTPUT 0U
|
||||||
#define SAFETY_HONDA 1
|
#define SAFETY_HONDA 1U
|
||||||
#define SAFETY_TOYOTA 2
|
#define SAFETY_TOYOTA 2U
|
||||||
#define SAFETY_GM 3
|
#define SAFETY_GM 3U
|
||||||
#define SAFETY_HONDA_BOSCH 4
|
#define SAFETY_HONDA_BOSCH 4U
|
||||||
#define SAFETY_FORD 5
|
#define SAFETY_FORD 5U
|
||||||
#define SAFETY_CADILLAC 6
|
#define SAFETY_CADILLAC 6U
|
||||||
#define SAFETY_HYUNDAI 7
|
#define SAFETY_HYUNDAI 7U
|
||||||
#define SAFETY_TESLA 8
|
#define SAFETY_TESLA 8U
|
||||||
#define SAFETY_CHRYSLER 9
|
#define SAFETY_CHRYSLER 9U
|
||||||
#define SAFETY_SUBARU 10
|
#define SAFETY_SUBARU 10U
|
||||||
#define SAFETY_GM_ASCM 0x1334
|
#define SAFETY_GM_ASCM 0x1334U
|
||||||
#define SAFETY_TOYOTA_IPAS 0x1335
|
#define SAFETY_TOYOTA_IPAS 0x1335U
|
||||||
#define SAFETY_ALLOUTPUT 0x1337
|
#define SAFETY_ALLOUTPUT 0x1337U
|
||||||
#define SAFETY_ELM327 0xE327
|
#define SAFETY_ELM327 0xE327U
|
||||||
|
|
||||||
const safety_hook_config safety_hook_registry[] = {
|
const safety_hook_config safety_hook_registry[] = {
|
||||||
{SAFETY_NOOUTPUT, &nooutput_hooks},
|
{SAFETY_NOOUTPUT, &nooutput_hooks},
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ const int CADILLAC_MAX_RATE_DOWN = 5;
|
|||||||
const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50;
|
const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50;
|
||||||
const int CADILLAC_DRIVER_TORQUE_FACTOR = 4;
|
const int CADILLAC_DRIVER_TORQUE_FACTOR = 4;
|
||||||
|
|
||||||
int cadillac_ign = 0;
|
bool cadillac_ign = 0;
|
||||||
int cadillac_cruise_engaged_last = 0;
|
int cadillac_cruise_engaged_last = 0;
|
||||||
int cadillac_rt_torque_last = 0;
|
int cadillac_rt_torque_last = 0;
|
||||||
const int cadillac_torque_msgs_n = 4;
|
const int cadillac_torque_msgs_n = 4;
|
||||||
int cadillac_desired_torque_last[CADILLAC_TORQUE_MSG_N] = {0};
|
int cadillac_desired_torque_last[CADILLAC_TORQUE_MSG_N] = {0};
|
||||||
uint32_t cadillac_ts_last = 0;
|
uint32_t cadillac_ts_last = 0;
|
||||||
int cadillac_supercruise_on = 0;
|
bool cadillac_supercruise_on = 0;
|
||||||
struct sample_t cadillac_torque_driver; // last few driver torques measured
|
struct sample_t cadillac_torque_driver; // last few driver torques measured
|
||||||
|
|
||||||
int cadillac_get_torque_idx(int addr, int array_size) {
|
int cadillac_get_torque_idx(int addr, int array_size) {
|
||||||
@@ -28,7 +28,8 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
int addr = GET_ADDR(to_push);
|
int addr = GET_ADDR(to_push);
|
||||||
|
|
||||||
if (addr == 356) {
|
if (addr == 356) {
|
||||||
int torque_driver_new = ((to_push->RDLR & 0x7) << 8) | ((to_push->RDLR >> 8) & 0xFF);
|
int torque_driver_new = ((GET_BYTE(to_push, 0) & 0x7U) << 8) | (GET_BYTE(to_push, 1));
|
||||||
|
|
||||||
torque_driver_new = to_signed(torque_driver_new, 11);
|
torque_driver_new = to_signed(torque_driver_new, 11);
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&cadillac_torque_driver, torque_driver_new);
|
update_sample(&cadillac_torque_driver, torque_driver_new);
|
||||||
@@ -36,12 +37,12 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// this message isn't all zeros when ignition is on
|
// this message isn't all zeros when ignition is on
|
||||||
if ((addr == 0x160) && (bus == 0)) {
|
if ((addr == 0x160) && (bus == 0)) {
|
||||||
cadillac_ign = to_push->RDLR > 0;
|
cadillac_ign = GET_BYTES_04(to_push) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter controls on rising edge of ACC, exit controls on ACC off
|
// enter controls on rising edge of ACC, exit controls on ACC off
|
||||||
if ((addr == 0x370) && (bus == 0)) {
|
if ((addr == 0x370) && (bus == 0)) {
|
||||||
int cruise_engaged = to_push->RDLR & 0x800000; // bit 23
|
int cruise_engaged = GET_BYTE(to_push, 2) & 0x80; // bit 23
|
||||||
if (cruise_engaged && !cadillac_cruise_engaged_last) {
|
if (cruise_engaged && !cadillac_cruise_engaged_last) {
|
||||||
controls_allowed = 1;
|
controls_allowed = 1;
|
||||||
}
|
}
|
||||||
@@ -53,7 +54,7 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// know supercruise mode and block openpilot msgs if on
|
// know supercruise mode and block openpilot msgs if on
|
||||||
if ((addr == 0x152) || (addr == 0x154)) {
|
if ((addr == 0x152) || (addr == 0x154)) {
|
||||||
cadillac_supercruise_on = (to_push->RDHR>>4) & 0x1;
|
cadillac_supercruise_on = (GET_BYTE(to_push, 4) & 0x10) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// steer cmd checks
|
// steer cmd checks
|
||||||
if ((addr == 0x151) || (addr == 0x152) || (addr == 0x153) || (addr == 0x154)) {
|
if ((addr == 0x151) || (addr == 0x152) || (addr == 0x153) || (addr == 0x154)) {
|
||||||
int desired_torque = ((to_send->RDLR & 0x3f) << 8) + ((to_send->RDLR & 0xff00) >> 8);
|
int desired_torque = ((GET_BYTE(to_send, 0) & 0x3f) << 8) | GET_BYTE(to_send, 1);
|
||||||
int violation = 0;
|
int violation = 0;
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
int idx = cadillac_get_torque_idx(addr, CADILLAC_TORQUE_MSG_N);
|
int idx = cadillac_get_torque_idx(addr, CADILLAC_TORQUE_MSG_N);
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// Measured eps torque
|
// Measured eps torque
|
||||||
if (addr == 544) {
|
if (addr == 544) {
|
||||||
uint32_t rdhr = to_push->RDHR;
|
int torque_meas_new = ((GET_BYTE(to_push, 4) & 0x7U) << 8) + GET_BYTE(to_push, 5) - 1024U;
|
||||||
int torque_meas_new = ((rdhr & 0x7U) << 8) + ((rdhr & 0xFF00U) >> 8) - 1024U;
|
|
||||||
|
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&chrysler_torque_meas, torque_meas_new);
|
update_sample(&chrysler_torque_meas, torque_meas_new);
|
||||||
@@ -27,7 +26,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// enter controls on rising edge of ACC, exit controls on ACC off
|
// enter controls on rising edge of ACC, exit controls on ACC off
|
||||||
if (addr == 0x1F4) {
|
if (addr == 0x1F4) {
|
||||||
int cruise_engaged = ((to_push->RDLR & 0x380000) >> 19) == 7;
|
int cruise_engaged = ((GET_BYTE(to_push, 2) & 0x38) >> 3) == 7;
|
||||||
if (cruise_engaged && !chrysler_cruise_engaged_last) {
|
if (cruise_engaged && !chrysler_cruise_engaged_last) {
|
||||||
controls_allowed = 1;
|
controls_allowed = 1;
|
||||||
}
|
}
|
||||||
@@ -57,8 +56,7 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// LKA STEER
|
// LKA STEER
|
||||||
if (addr == 0x292) {
|
if (addr == 0x292) {
|
||||||
uint32_t rdlr = to_send->RDLR;
|
int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1) - 1024U;
|
||||||
int desired_torque = ((rdlr & 0x7U) << 8) + ((rdlr & 0xFF00U) >> 8) - 1024U;
|
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
static int elm327_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
static int elm327_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
||||||
|
|
||||||
int tx = 1;
|
int tx = 1;
|
||||||
int bus = GET_BUS(to_send);
|
|
||||||
int addr = GET_ADDR(to_send);
|
int addr = GET_ADDR(to_send);
|
||||||
int len = GET_LEN(to_send);
|
int len = GET_LEN(to_send);
|
||||||
|
|
||||||
//All ELM traffic must appear on CAN0
|
|
||||||
if (bus != 0) {
|
|
||||||
tx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//All ISO 15765-4 messages must be 8 bytes long
|
//All ISO 15765-4 messages must be 8 bytes long
|
||||||
if (len != 8) {
|
if (len != 8) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
int ford_brake_prev = 0;
|
int ford_brake_prev = 0;
|
||||||
int ford_gas_prev = 0;
|
int ford_gas_prev = 0;
|
||||||
int ford_is_moving = 0;
|
bool ford_moving = false;
|
||||||
|
|
||||||
static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
||||||
|
|
||||||
@@ -17,14 +17,16 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
if (addr == 0x217) {
|
if (addr == 0x217) {
|
||||||
// wheel speeds are 14 bits every 16
|
// wheel speeds are 14 bits every 16
|
||||||
ford_is_moving = 0xFCFF & (to_push->RDLR | (to_push->RDLR >> 16) |
|
ford_moving = false;
|
||||||
to_push->RDHR | (to_push->RDHR >> 16));
|
for (int i = 0; i < 8; i += 2) {
|
||||||
|
ford_moving |= GET_BYTE(to_push, i) | (GET_BYTE(to_push, (int)(i + 1)) & 0xFCU);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// state machine to enter and exit controls
|
// state machine to enter and exit controls
|
||||||
if (addr == 0x83) {
|
if (addr == 0x83) {
|
||||||
bool cancel = (to_push->RDLR >> 8) & 0x1;
|
bool cancel = GET_BYTE(to_push, 1) & 0x1;
|
||||||
bool set_or_resume = (to_push->RDLR >> 28) & 0x3;
|
bool set_or_resume = GET_BYTE(to_push, 3) & 0x30;
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -36,8 +38,8 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// exit controls on rising edge of brake press or on brake press when
|
// exit controls on rising edge of brake press or on brake press when
|
||||||
// speed > 0
|
// speed > 0
|
||||||
if (addr == 0x165) {
|
if (addr == 0x165) {
|
||||||
int brake = to_push->RDLR & 0x20;
|
int brake = GET_BYTE(to_push, 0) & 0x20;
|
||||||
if (brake && (!(ford_brake_prev) || ford_is_moving)) {
|
if (brake && (!(ford_brake_prev) || ford_moving)) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
ford_brake_prev = brake;
|
ford_brake_prev = brake;
|
||||||
@@ -45,7 +47,7 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// exit controls on rising edge of gas press
|
// exit controls on rising edge of gas press
|
||||||
if (addr == 0x204) {
|
if (addr == 0x204) {
|
||||||
int gas = to_push->RDLR & 0xFF03;
|
int gas = (GET_BYTE(to_push, 0) & 0x03) | GET_BYTE(to_push, 1);
|
||||||
if (gas && !(ford_gas_prev)) {
|
if (gas && !(ford_gas_prev)) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -64,7 +66,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
int tx = 1;
|
int tx = 1;
|
||||||
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
||||||
// and the the latching controls_allowed flag is True
|
// and the the latching controls_allowed flag is True
|
||||||
int pedal_pressed = ford_gas_prev || (ford_brake_prev && ford_is_moving);
|
int pedal_pressed = ford_gas_prev || (ford_brake_prev && ford_moving);
|
||||||
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
|
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
|
||||||
int addr = GET_ADDR(to_send);
|
int addr = GET_ADDR(to_send);
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
if (addr == 0x3CA) {
|
if (addr == 0x3CA) {
|
||||||
if (!current_controls_allowed) {
|
if (!current_controls_allowed) {
|
||||||
// bits 7-4 need to be 0xF to disallow lkas commands
|
// bits 7-4 need to be 0xF to disallow lkas commands
|
||||||
if (((to_send->RDLR >> 4) & 0xF) != 0xF) {
|
if ((GET_BYTE(to_send, 0) & 0xF0) != 0xF0) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +83,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// FORCE CANCEL: safety check only relevant when spamming the cancel button
|
// FORCE CANCEL: safety check only relevant when spamming the cancel button
|
||||||
// ensuring that set and resume aren't sent
|
// ensuring that set and resume aren't sent
|
||||||
if (addr == 0x83) {
|
if (addr == 0x83) {
|
||||||
if (((to_send->RDLR >> 28) & 0x3) != 0) {
|
if ((GET_BYTE(to_send, 3) & 0x30) != 0) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const int GM_MAX_BRAKE = 350;
|
|||||||
|
|
||||||
int gm_brake_prev = 0;
|
int gm_brake_prev = 0;
|
||||||
int gm_gas_prev = 0;
|
int gm_gas_prev = 0;
|
||||||
int gm_speed = 0;
|
bool gm_moving = false;
|
||||||
// silence everything if stock car control ECUs are still online
|
// silence everything if stock car control ECUs are still online
|
||||||
bool gm_ascm_detected = 0;
|
bool gm_ascm_detected = 0;
|
||||||
bool gm_ignition_started = 0;
|
bool gm_ignition_started = 0;
|
||||||
@@ -35,7 +35,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
int addr = GET_ADDR(to_push);
|
int addr = GET_ADDR(to_push);
|
||||||
|
|
||||||
if (addr == 388) {
|
if (addr == 388) {
|
||||||
int torque_driver_new = (((to_push->RDHR >> 16) & 0x7) << 8) | ((to_push->RDHR >> 24) & 0xFF);
|
int torque_driver_new = ((GET_BYTE(to_push, 6) & 0x7) << 8) | GET_BYTE(to_push, 7);
|
||||||
torque_driver_new = to_signed(torque_driver_new, 11);
|
torque_driver_new = to_signed(torque_driver_new, 11);
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&gm_torque_driver, torque_driver_new);
|
update_sample(&gm_torque_driver, torque_driver_new);
|
||||||
@@ -44,14 +44,14 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
if ((addr == 0x1F1) && (bus_number == 0)) {
|
if ((addr == 0x1F1) && (bus_number == 0)) {
|
||||||
//Bit 5 should be ignition "on"
|
//Bit 5 should be ignition "on"
|
||||||
//Backup plan is Bit 2 (accessory power)
|
//Backup plan is Bit 2 (accessory power)
|
||||||
bool ign = ((to_push->RDLR) & 0x20) != 0;
|
bool ign = (GET_BYTE(to_push, 0) & 0x20) != 0;
|
||||||
gm_ignition_started = ign;
|
gm_ignition_started = ign;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sample speed, really only care if car is moving or not
|
// sample speed, really only care if car is moving or not
|
||||||
// rear left wheel speed
|
// rear left wheel speed
|
||||||
if (addr == 842) {
|
if (addr == 842) {
|
||||||
gm_speed = to_push->RDLR & 0xFFFF;
|
gm_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if ASCM or LKA camera are online
|
// Check if ASCM or LKA camera are online
|
||||||
@@ -65,7 +65,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// ACC steering wheel buttons
|
// ACC steering wheel buttons
|
||||||
if (addr == 481) {
|
if (addr == 481) {
|
||||||
int button = (to_push->RDHR >> 12) & 0x7;
|
int button = (GET_BYTE(to_push, 5) & 0x70) >> 4;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case 2: // resume
|
case 2: // resume
|
||||||
case 3: // set
|
case 3: // set
|
||||||
@@ -82,13 +82,13 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// exit controls on rising edge of brake press or on brake press when
|
// exit controls on rising edge of brake press or on brake press when
|
||||||
// speed > 0
|
// speed > 0
|
||||||
if (addr == 241) {
|
if (addr == 241) {
|
||||||
int brake = (to_push->RDLR & 0xFF00) >> 8;
|
int brake = GET_BYTE(to_push, 1);
|
||||||
// Brake pedal's potentiometer returns near-zero reading
|
// Brake pedal's potentiometer returns near-zero reading
|
||||||
// even when pedal is not pressed
|
// even when pedal is not pressed
|
||||||
if (brake < 10) {
|
if (brake < 10) {
|
||||||
brake = 0;
|
brake = 0;
|
||||||
}
|
}
|
||||||
if (brake && (!gm_brake_prev || gm_speed)) {
|
if (brake && (!gm_brake_prev || gm_moving)) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
gm_brake_prev = brake;
|
gm_brake_prev = brake;
|
||||||
@@ -96,7 +96,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// exit controls on rising edge of gas press
|
// exit controls on rising edge of gas press
|
||||||
if (addr == 417) {
|
if (addr == 417) {
|
||||||
int gas = to_push->RDHR & 0xFF0000;
|
int gas = GET_BYTE(to_push, 6);
|
||||||
if (gas && !gm_gas_prev && long_controls_allowed) {
|
if (gas && !gm_gas_prev && long_controls_allowed) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// exit controls on regen paddle
|
// exit controls on regen paddle
|
||||||
if (addr == 189) {
|
if (addr == 189) {
|
||||||
bool regen = to_push->RDLR & 0x20;
|
bool regen = GET_BYTE(to_push, 0) & 0x20;
|
||||||
if (regen) {
|
if (regen) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -129,15 +129,14 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
||||||
// and the the latching controls_allowed flag is True
|
// and the the latching controls_allowed flag is True
|
||||||
int pedal_pressed = gm_gas_prev || (gm_brake_prev && gm_speed);
|
int pedal_pressed = gm_gas_prev || (gm_brake_prev && gm_moving);
|
||||||
bool current_controls_allowed = controls_allowed && !pedal_pressed;
|
bool current_controls_allowed = controls_allowed && !pedal_pressed;
|
||||||
|
|
||||||
int addr = GET_ADDR(to_send);
|
int addr = GET_ADDR(to_send);
|
||||||
|
|
||||||
// BRAKE: safety check
|
// BRAKE: safety check
|
||||||
if (addr == 789) {
|
if (addr == 789) {
|
||||||
uint32_t rdlr = to_send->RDLR;
|
int brake = ((GET_BYTE(to_send, 0) & 0xFU) << 8) + GET_BYTE(to_send, 1);
|
||||||
int brake = ((rdlr & 0xFU) << 8) + ((rdlr & 0xFF00U) >> 8);
|
|
||||||
brake = (0x1000 - brake) & 0xFFF;
|
brake = (0x1000 - brake) & 0xFFF;
|
||||||
if (!current_controls_allowed || !long_controls_allowed) {
|
if (!current_controls_allowed || !long_controls_allowed) {
|
||||||
if (brake != 0) {
|
if (brake != 0) {
|
||||||
@@ -151,8 +150,7 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// LKA STEER: safety check
|
// LKA STEER: safety check
|
||||||
if (addr == 384) {
|
if (addr == 384) {
|
||||||
uint32_t rdlr = to_send->RDLR;
|
int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1);
|
||||||
int desired_torque = ((rdlr & 0x7U) << 8) + ((rdlr & 0xFF00U) >> 8);
|
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
desired_torque = to_signed(desired_torque, 11);
|
desired_torque = to_signed(desired_torque, 11);
|
||||||
@@ -205,12 +203,11 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// GAS/REGEN: safety check
|
// GAS/REGEN: safety check
|
||||||
if (addr == 715) {
|
if (addr == 715) {
|
||||||
uint32_t rdlr = to_send->RDLR;
|
int gas_regen = ((GET_BYTE(to_send, 2) & 0x7FU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3);
|
||||||
int gas_regen = ((rdlr & 0x7F0000U) >> 11) + ((rdlr & 0xF8000000U) >> 27);
|
|
||||||
// Disabled message is !engaed with gas
|
// Disabled message is !engaed with gas
|
||||||
// value that corresponds to max regen.
|
// value that corresponds to max regen.
|
||||||
if (!current_controls_allowed || !long_controls_allowed) {
|
if (!current_controls_allowed || !long_controls_allowed) {
|
||||||
bool apply = (rdlr & 1U) != 0U;
|
bool apply = GET_BYTE(to_send, 0) & 1U;
|
||||||
if (apply || (gas_regen != GM_MAX_REGEN)) {
|
if (apply || (gas_regen != GM_MAX_REGEN)) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ static int gm_ascm_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
|||||||
// block 0x315 and 0x2cb, which are the brake and accel commands from ASCM1
|
// block 0x315 and 0x2cb, which are the brake and accel commands from ASCM1
|
||||||
//if ((addr == 0x152) || (addr == 0x154) || (addr == 0x315) || (addr == 0x2cb)) {
|
//if ((addr == 0x152) || (addr == 0x154) || (addr == 0x315) || (addr == 0x2cb)) {
|
||||||
if ((addr == 0x152) || (addr == 0x154)) {
|
if ((addr == 0x152) || (addr == 0x154)) {
|
||||||
int supercruise_on = (to_fwd->RDHR >> 4) & 0x1; // bit 36
|
bool supercruise_on = (GET_BYTE(to_fwd, 4) & 0x10) != 0; // bit 36
|
||||||
if (!supercruise_on) {
|
if (!supercruise_on) {
|
||||||
bus_fwd = -1;
|
bus_fwd = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 328; // ratio between offset and gain from dbc file
|
const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 328; // ratio between offset and gain from dbc file
|
||||||
int honda_brake_prev = 0;
|
int honda_brake_prev = 0;
|
||||||
int honda_gas_prev = 0;
|
int honda_gas_prev = 0;
|
||||||
int honda_ego_speed = 0;
|
bool honda_moving = false;
|
||||||
bool honda_bosch_hardware = false;
|
bool honda_bosch_hardware = false;
|
||||||
bool honda_alt_brake_msg = false;
|
bool honda_alt_brake_msg = false;
|
||||||
|
|
||||||
@@ -22,13 +22,13 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// sample speed
|
// sample speed
|
||||||
if (addr == 0x158) {
|
if (addr == 0x158) {
|
||||||
// first 2 bytes
|
// first 2 bytes
|
||||||
honda_ego_speed = to_push->RDLR & 0xFFFF;
|
honda_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// state machine to enter and exit controls
|
// state machine to enter and exit controls
|
||||||
// 0x1A6 for the ILX, 0x296 for the Civic Touring
|
// 0x1A6 for the ILX, 0x296 for the Civic Touring
|
||||||
if ((addr == 0x1A6) || (addr == 0x296)) {
|
if ((addr == 0x1A6) || (addr == 0x296)) {
|
||||||
int button = (to_push->RDLR & 0xE0) >> 5;
|
int button = (GET_BYTE(to_push, 0) & 0xE0) >> 5;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case 2: // cancel
|
case 2: // cancel
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
@@ -48,14 +48,11 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// in these cases, this is used instead.
|
// in these cases, this is used instead.
|
||||||
// most hondas: 0x17C bit 53
|
// most hondas: 0x17C bit 53
|
||||||
// accord, crv: 0x1BE bit 4
|
// accord, crv: 0x1BE bit 4
|
||||||
#define IS_USER_BRAKE_MSG(addr) (!honda_alt_brake_msg ? ((addr) == 0x17C) : ((addr) == 0x1BE))
|
// exit controls on rising edge of brake press or on brake press when speed > 0
|
||||||
#define USER_BRAKE_VALUE(to_push) (!honda_alt_brake_msg ? ((to_push)->RDHR & 0x200000) : ((to_push)->RDLR & 0x10))
|
bool is_user_brake_msg = honda_alt_brake_msg ? ((addr) == 0x1BE) : ((addr) == 0x17C);
|
||||||
// exit controls on rising edge of brake press or on brake press when
|
|
||||||
// speed > 0
|
|
||||||
bool is_user_brake_msg = IS_USER_BRAKE_MSG(addr); // needed to enforce type
|
|
||||||
if (is_user_brake_msg) {
|
if (is_user_brake_msg) {
|
||||||
int brake = USER_BRAKE_VALUE(to_push);
|
int brake = honda_alt_brake_msg ? (GET_BYTE((to_push), 0) & 0x10) : (GET_BYTE((to_push), 6) & 0x20);
|
||||||
if (brake && (!(honda_brake_prev) || honda_ego_speed)) {
|
if (brake && (!(honda_brake_prev) || honda_moving)) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
honda_brake_prev = brake;
|
honda_brake_prev = brake;
|
||||||
@@ -65,7 +62,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// length check because bosch hardware also uses this id (0x201 w/ len = 8)
|
// length check because bosch hardware also uses this id (0x201 w/ len = 8)
|
||||||
if ((addr == 0x201) && (len == 6)) {
|
if ((addr == 0x201) && (len == 6)) {
|
||||||
gas_interceptor_detected = 1;
|
gas_interceptor_detected = 1;
|
||||||
int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
|
int gas_interceptor = GET_INTERCEPTOR(to_push);
|
||||||
if ((gas_interceptor > HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
|
if ((gas_interceptor > HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
|
||||||
(gas_interceptor_prev <= HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
|
(gas_interceptor_prev <= HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
|
||||||
long_controls_allowed) {
|
long_controls_allowed) {
|
||||||
@@ -77,7 +74,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// exit controls on rising edge of gas press if no interceptor
|
// exit controls on rising edge of gas press if no interceptor
|
||||||
if (!gas_interceptor_detected) {
|
if (!gas_interceptor_detected) {
|
||||||
if (addr == 0x17C) {
|
if (addr == 0x17C) {
|
||||||
int gas = to_push->RDLR & 0xFF;
|
int gas = GET_BYTE(to_push, 0);
|
||||||
if (gas && !(honda_gas_prev) && long_controls_allowed) {
|
if (gas && !(honda_gas_prev) && long_controls_allowed) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -101,17 +98,18 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
||||||
// and the the latching controls_allowed flag is True
|
// and the the latching controls_allowed flag is True
|
||||||
int pedal_pressed = honda_gas_prev || (gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD) ||
|
int pedal_pressed = honda_gas_prev || (gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD) ||
|
||||||
(honda_brake_prev && honda_ego_speed);
|
(honda_brake_prev && honda_moving);
|
||||||
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
|
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
|
||||||
|
|
||||||
// BRAKE: safety check
|
// BRAKE: safety check
|
||||||
if (addr == 0x1FA) {
|
if (addr == 0x1FA) {
|
||||||
|
int brake = (GET_BYTE(to_send, 0) << 2) + (GET_BYTE(to_send, 1) & 0x3);
|
||||||
if (!current_controls_allowed || !long_controls_allowed) {
|
if (!current_controls_allowed || !long_controls_allowed) {
|
||||||
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) {
|
if (brake != 0) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((to_send->RDLR & 0xFFFFFF3F) != to_send->RDLR) {
|
if (brake > 255) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +117,8 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// STEER: safety check
|
// STEER: safety check
|
||||||
if ((addr == 0xE4) || (addr == 0x194)) {
|
if ((addr == 0xE4) || (addr == 0x194)) {
|
||||||
if (!current_controls_allowed) {
|
if (!current_controls_allowed) {
|
||||||
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) {
|
bool steer_applied = GET_BYTE(to_send, 0) | GET_BYTE(to_send, 1);
|
||||||
|
if (steer_applied) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +127,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// GAS: safety check
|
// GAS: safety check
|
||||||
if (addr == 0x200) {
|
if (addr == 0x200) {
|
||||||
if (!current_controls_allowed || !long_controls_allowed) {
|
if (!current_controls_allowed || !long_controls_allowed) {
|
||||||
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) {
|
if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,9 +136,10 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// FORCE CANCEL: safety check only relevant when spamming the cancel button in Bosch HW
|
// FORCE CANCEL: safety check only relevant when spamming the cancel button in Bosch HW
|
||||||
// ensuring that only the cancel button press is sent (VAL 2) when controls are off.
|
// ensuring that only the cancel button press is sent (VAL 2) when controls are off.
|
||||||
// This avoids unintended engagements while still allowing resume spam
|
// This avoids unintended engagements while still allowing resume spam
|
||||||
|
int bus_pt = ((hw_type == HW_TYPE_BLACK_PANDA) && honda_bosch_hardware)? 1 : 0;
|
||||||
if ((addr == 0x296) && honda_bosch_hardware &&
|
if ((addr == 0x296) && honda_bosch_hardware &&
|
||||||
!current_controls_allowed && (bus == 0)) {
|
!current_controls_allowed && (bus == bus_pt)) {
|
||||||
if (((to_send->RDLR >> 5) & 0x7) != 2) {
|
if (((GET_BYTE(to_send, 0) >> 5) & 0x7) != 2) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,15 +187,17 @@ static int honda_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
|||||||
|
|
||||||
static int honda_bosch_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
static int honda_bosch_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
||||||
int bus_fwd = -1;
|
int bus_fwd = -1;
|
||||||
|
int bus_rdr_cam = (hw_type == HW_TYPE_BLACK_PANDA) ? 2 : 1; // radar bus, camera side
|
||||||
|
int bus_rdr_car = (hw_type == HW_TYPE_BLACK_PANDA) ? 0 : 2; // radar bus, car side
|
||||||
|
|
||||||
if (bus_num == 2) {
|
if (bus_num == bus_rdr_car) {
|
||||||
bus_fwd = 1;
|
bus_fwd = bus_rdr_cam;
|
||||||
}
|
}
|
||||||
if (bus_num == 1) {
|
if (bus_num == bus_rdr_cam) {
|
||||||
int addr = GET_ADDR(to_fwd);
|
int addr = GET_ADDR(to_fwd);
|
||||||
int is_lkas_msg = (addr == 0xE4) || (addr == 0x33D);
|
int is_lkas_msg = (addr == 0xE4) || (addr == 0x33D);
|
||||||
if (!is_lkas_msg) {
|
if (!is_lkas_msg) {
|
||||||
bus_fwd = 2;
|
bus_fwd = bus_rdr_car;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bus_fwd;
|
return bus_fwd;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
int addr = GET_ADDR(to_push);
|
int addr = GET_ADDR(to_push);
|
||||||
|
|
||||||
if (addr == 897) {
|
if (addr == 897) {
|
||||||
int torque_driver_new = ((to_push->RDLR >> 11) & 0xfff) - 2048;
|
int torque_driver_new = ((GET_BYTES_04(to_push) >> 11) & 0xfff) - 2048;
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&hyundai_torque_driver, torque_driver_new);
|
update_sample(&hyundai_torque_driver, torque_driver_new);
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// enter controls on rising edge of ACC, exit controls on ACC off
|
// enter controls on rising edge of ACC, exit controls on ACC off
|
||||||
if (addr == 1057) {
|
if (addr == 1057) {
|
||||||
// 2 bits: 13-14
|
// 2 bits: 13-14
|
||||||
int cruise_engaged = (to_push->RDLR >> 13) & 0x3;
|
int cruise_engaged = (GET_BYTES_04(to_push) >> 13) & 0x3;
|
||||||
if (cruise_engaged && !hyundai_cruise_engaged_last) {
|
if (cruise_engaged && !hyundai_cruise_engaged_last) {
|
||||||
controls_allowed = 1;
|
controls_allowed = 1;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// LKA STEER: safety check
|
// LKA STEER: safety check
|
||||||
if (addr == 832) {
|
if (addr == 832) {
|
||||||
int desired_torque = ((to_send->RDLR >> 16) & 0x7ff) - 1024;
|
int desired_torque = ((GET_BYTES_04(to_send) >> 16) & 0x7ff) - 1024;
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// This avoids unintended engagements while still allowing resume spam
|
// This avoids unintended engagements while still allowing resume spam
|
||||||
// TODO: fix bug preventing the button msg to be fwd'd on bus 2
|
// TODO: fix bug preventing the button msg to be fwd'd on bus 2
|
||||||
//if ((addr == 1265) && !controls_allowed && (bus == 0) {
|
//if ((addr == 1265) && !controls_allowed && (bus == 0) {
|
||||||
// if ((to_send->RDLR & 0x7) != 4) {
|
// if ((GET_BYTES_04(to_send) & 0x7) != 4) {
|
||||||
// tx = 0;
|
// tx = 0;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
int addr = GET_ADDR(to_push);
|
int addr = GET_ADDR(to_push);
|
||||||
|
|
||||||
if ((addr == 0x119) && (bus == 0)){
|
if ((addr == 0x119) && (bus == 0)){
|
||||||
int torque_driver_new = ((to_push->RDLR >> 16) & 0x7FF);
|
int torque_driver_new = ((GET_BYTES_04(to_push) >> 16) & 0x7FF);
|
||||||
torque_driver_new = to_signed(torque_driver_new, 11);
|
torque_driver_new = to_signed(torque_driver_new, 11);
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&subaru_torque_driver, torque_driver_new);
|
update_sample(&subaru_torque_driver, torque_driver_new);
|
||||||
@@ -28,7 +28,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// enter controls on rising edge of ACC, exit controls on ACC off
|
// enter controls on rising edge of ACC, exit controls on ACC off
|
||||||
if ((addr == 0x240) && (bus == 0)) {
|
if ((addr == 0x240) && (bus == 0)) {
|
||||||
int cruise_engaged = (to_push->RDHR >> 9) & 1;
|
int cruise_engaged = GET_BYTE(to_push, 5) & 2;
|
||||||
if (cruise_engaged && !subaru_cruise_engaged_last) {
|
if (cruise_engaged && !subaru_cruise_engaged_last) {
|
||||||
controls_allowed = 1;
|
controls_allowed = 1;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ static int subaru_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// steer cmd checks
|
// steer cmd checks
|
||||||
if (addr == 0x122) {
|
if (addr == 0x122) {
|
||||||
int desired_torque = ((to_send->RDLR >> 16) & 0x1FFF);
|
int desired_torque = ((GET_BYTES_04(to_send) >> 16) & 0x1FFF);
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
desired_torque = to_signed(desired_torque, 13);
|
desired_torque = to_signed(desired_torque, 13);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
if (addr == 0x45) {
|
if (addr == 0x45) {
|
||||||
// 6 bits starting at position 0
|
// 6 bits starting at position 0
|
||||||
int lever_position = (to_push->RDLR & 0x3F);
|
int lever_position = GET_BYTE(to_push, 0) & 0x3F;
|
||||||
if (lever_position == 2) { // pull forward
|
if (lever_position == 2) { // pull forward
|
||||||
// activate openpilot
|
// activate openpilot
|
||||||
controls_allowed = 1;
|
controls_allowed = 1;
|
||||||
@@ -69,7 +69,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// Detect drive rail on (ignition) (start recording)
|
// Detect drive rail on (ignition) (start recording)
|
||||||
if (addr == 0x348) {
|
if (addr == 0x348) {
|
||||||
// GTW_status
|
// GTW_status
|
||||||
int drive_rail_on = (to_push->RDLR & 0x0001);
|
int drive_rail_on = GET_BYTE(to_push, 0) & 0x1;
|
||||||
tesla_ignition_started = drive_rail_on == 1;
|
tesla_ignition_started = drive_rail_on == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +77,12 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// DI_torque2::DI_brakePedal 0x118
|
// DI_torque2::DI_brakePedal 0x118
|
||||||
if (addr == 0x118) {
|
if (addr == 0x118) {
|
||||||
// 1 bit at position 16
|
// 1 bit at position 16
|
||||||
if ((((to_push->RDLR & 0x8000)) >> 15) == 1) {
|
if ((GET_BYTE(to_push, 1) & 0x80) != 0) {
|
||||||
// disable break cancel by commenting line below
|
// disable break cancel by commenting line below
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
//get vehicle speed in m/s. Tesla gives MPH
|
//get vehicle speed in m/s. Tesla gives MPH
|
||||||
tesla_speed = ((((((to_push->RDLR >> 24) & 0xF) << 8) + ((to_push->RDLR >> 16) & 0xFF)) * 0.05) - 25) * 1.609 / 3.6;
|
tesla_speed = (((((GET_BYTE(to_push, 3) & 0xF) << 8) + GET_BYTE(to_push, 2)) * 0.05) - 25) * 1.609 / 3.6;
|
||||||
if (tesla_speed < 0) {
|
if (tesla_speed < 0) {
|
||||||
tesla_speed = 0;
|
tesla_speed = 0;
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// EPAS_sysStatus::EPAS_eacStatus 0x370
|
// EPAS_sysStatus::EPAS_eacStatus 0x370
|
||||||
if (addr == 0x370) {
|
if (addr == 0x370) {
|
||||||
// if EPAS_eacStatus is not 1 or 2, disable control
|
// if EPAS_eacStatus is not 1 or 2, disable control
|
||||||
eac_status = ((to_push->RDHR >> 21)) & 0x7;
|
eac_status = (GET_BYTE(to_push, 6) >> 5) & 0x7;
|
||||||
// For human steering override we must not disable controls when eac_status == 0
|
// For human steering override we must not disable controls when eac_status == 0
|
||||||
// Additional safety: we could only allow eac_status == 0 when we have human steering allowed
|
// Additional safety: we could only allow eac_status == 0 when we have human steering allowed
|
||||||
if (controls_allowed && (eac_status != 0) && (eac_status != 1) && (eac_status != 2)) {
|
if (controls_allowed && (eac_status != 0) && (eac_status != 1) && (eac_status != 2)) {
|
||||||
@@ -102,7 +102,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
}
|
}
|
||||||
//get latest steering wheel angle
|
//get latest steering wheel angle
|
||||||
if (addr == 0x00E) {
|
if (addr == 0x00E) {
|
||||||
float angle_meas_now = (int)(((((to_push->RDLR & 0x3F) << 8) + ((to_push->RDLR >> 8) & 0xFF)) * 0.1) - 819.2);
|
float angle_meas_now = (int)(((((GET_BYTE(to_push, 0) & 0x3F) << 8) + GET_BYTE(to_push, 1)) * 0.1) - 819.2);
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_ts_angle_last);
|
uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_ts_angle_last);
|
||||||
|
|
||||||
@@ -146,10 +146,10 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// do not transmit CAN message if steering angle too high
|
// do not transmit CAN message if steering angle too high
|
||||||
// DAS_steeringControl::DAS_steeringAngleRequest
|
// DAS_steeringControl::DAS_steeringAngleRequest
|
||||||
if (addr == 0x488) {
|
if (addr == 0x488) {
|
||||||
float angle_raw = ((to_send->RDLR & 0x7F) << 8) + ((to_send->RDLR & 0xFF00) >> 8);
|
float angle_raw = ((GET_BYTE(to_send, 0) & 0x7F) << 8) + GET_BYTE(to_send, 1);
|
||||||
float desired_angle = (angle_raw * 0.1) - 1638.35;
|
float desired_angle = (angle_raw * 0.1) - 1638.35;
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
int st_enabled = (to_send->RDLR & 0x400000) >> 22;
|
int st_enabled = GET_BYTE(to_send, 2) & 0x40;
|
||||||
|
|
||||||
if (st_enabled == 0) {
|
if (st_enabled == 0) {
|
||||||
//steering is not enabled, do not check angles and do send
|
//steering is not enabled, do not check angles and do send
|
||||||
@@ -204,10 +204,10 @@ static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
|||||||
bus_fwd = 2; // Custom EPAS bus
|
bus_fwd = 2; // Custom EPAS bus
|
||||||
}
|
}
|
||||||
if (addr == 0x101) {
|
if (addr == 0x101) {
|
||||||
to_fwd->RDLR = to_fwd->RDLR | 0x4000; // 0x4000: WITH_ANGLE, 0xC000: WITH_BOTH (angle and torque)
|
to_fwd->RDLR = GET_BYTES_04(to_fwd) | 0x4000; // 0x4000: WITH_ANGLE, 0xC000: WITH_BOTH (angle and torque)
|
||||||
uint32_t checksum = (((to_fwd->RDLR & 0xFF00) >> 8) + (to_fwd->RDLR & 0xFF) + 2) & 0xFF;
|
uint32_t checksum = (GET_BYTE(to_fwd, 1) + GET_BYTE(to_fwd, 0) + 2) & 0xFF;
|
||||||
to_fwd->RDLR = to_fwd->RDLR & 0xFFFF;
|
to_fwd->RDLR = GET_BYTES_04(to_fwd) & 0xFFFF;
|
||||||
to_fwd->RDLR = to_fwd->RDLR + (checksum << 16);
|
to_fwd->RDLR = GET_BYTES_04(to_fwd) + (checksum << 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bus_num == 2) {
|
if (bus_num == 2) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// get eps motor torque (0.66 factor in dbc)
|
// get eps motor torque (0.66 factor in dbc)
|
||||||
if (addr == 0x260) {
|
if (addr == 0x260) {
|
||||||
int torque_meas_new = (((to_push->RDHR) & 0xFF00) | ((to_push->RDHR >> 16) & 0xFF));
|
int torque_meas_new = (GET_BYTE(to_push, 5) << 8) | GET_BYTE(to_push, 6);
|
||||||
torque_meas_new = to_signed(torque_meas_new, 16);
|
torque_meas_new = to_signed(torque_meas_new, 16);
|
||||||
|
|
||||||
// scale by dbc_factor
|
// scale by dbc_factor
|
||||||
@@ -56,7 +56,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// enter controls on rising edge of ACC, exit controls on ACC off
|
// enter controls on rising edge of ACC, exit controls on ACC off
|
||||||
if (addr == 0x1D2) {
|
if (addr == 0x1D2) {
|
||||||
// 5th bit is CRUISE_ACTIVE
|
// 5th bit is CRUISE_ACTIVE
|
||||||
int cruise_engaged = to_push->RDLR & 0x20;
|
int cruise_engaged = GET_BYTE(to_push, 0) & 0x20;
|
||||||
if (!cruise_engaged) {
|
if (!cruise_engaged) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
// exit controls on rising edge of interceptor gas press
|
// exit controls on rising edge of interceptor gas press
|
||||||
if (addr == 0x201) {
|
if (addr == 0x201) {
|
||||||
gas_interceptor_detected = 1;
|
gas_interceptor_detected = 1;
|
||||||
int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
|
int gas_interceptor = GET_INTERCEPTOR(to_push);
|
||||||
if ((gas_interceptor > TOYOTA_GAS_INTERCEPTOR_THRESHOLD) &&
|
if ((gas_interceptor > TOYOTA_GAS_INTERCEPTOR_THRESHOLD) &&
|
||||||
(gas_interceptor_prev <= TOYOTA_GAS_INTERCEPTOR_THRESHOLD) &&
|
(gas_interceptor_prev <= TOYOTA_GAS_INTERCEPTOR_THRESHOLD) &&
|
||||||
long_controls_allowed) {
|
long_controls_allowed) {
|
||||||
@@ -80,7 +80,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// exit controls on rising edge of gas press
|
// exit controls on rising edge of gas press
|
||||||
if (addr == 0x2C1) {
|
if (addr == 0x2C1) {
|
||||||
int gas = (to_push->RDHR >> 16) & 0xFF;
|
int gas = GET_BYTE(to_push, 6) & 0xFF;
|
||||||
if ((gas > 0) && (toyota_gas_prev == 0) && !gas_interceptor_detected && long_controls_allowed) {
|
if ((gas > 0) && (toyota_gas_prev == 0) && !gas_interceptor_detected && long_controls_allowed) {
|
||||||
controls_allowed = 0;
|
controls_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
// GAS PEDAL: safety check
|
// GAS PEDAL: safety check
|
||||||
if (addr == 0x200) {
|
if (addr == 0x200) {
|
||||||
if (!controls_allowed || !long_controls_allowed) {
|
if (!controls_allowed || !long_controls_allowed) {
|
||||||
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) {
|
if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) {
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// ACCEL: safety check on byte 1-2
|
// ACCEL: safety check on byte 1-2
|
||||||
if (addr == 0x343) {
|
if (addr == 0x343) {
|
||||||
int desired_accel = ((to_send->RDLR & 0xFF) << 8) | ((to_send->RDLR >> 8) & 0xFF);
|
int desired_accel = (GET_BYTE(to_send, 0) << 8) | GET_BYTE(to_send, 1);
|
||||||
desired_accel = to_signed(desired_accel, 16);
|
desired_accel = to_signed(desired_accel, 16);
|
||||||
if (!controls_allowed || !long_controls_allowed) {
|
if (!controls_allowed || !long_controls_allowed) {
|
||||||
if (desired_accel != 0) {
|
if (desired_accel != 0) {
|
||||||
@@ -138,7 +138,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
|
|
||||||
// STEER: safety check on bytes 2-3
|
// STEER: safety check on bytes 2-3
|
||||||
if (addr == 0x2E4) {
|
if (addr == 0x2E4) {
|
||||||
int desired_torque = (to_send->RDLR & 0xFF00) | ((to_send->RDLR >> 16) & 0xFF);
|
int desired_torque = (GET_BYTE(to_send, 1) << 8) | GET_BYTE(to_send, 2);
|
||||||
desired_torque = to_signed(desired_torque, 16);
|
desired_torque = to_signed(desired_torque, 16);
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
if (addr == 0x260) {
|
if (addr == 0x260) {
|
||||||
// get driver steering torque
|
// get driver steering torque
|
||||||
int16_t torque_driver_new = (((to_push->RDLR) & 0xFF00) | ((to_push->RDLR >> 16) & 0xFF));
|
int16_t torque_driver_new = (GET_BYTE(to_push, 1) << 8) | GET_BYTE(to_push, 2);
|
||||||
|
|
||||||
// update array of samples
|
// update array of samples
|
||||||
update_sample(&torque_driver, torque_driver_new);
|
update_sample(&torque_driver, torque_driver_new);
|
||||||
@@ -47,7 +47,7 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// get steer angle
|
// get steer angle
|
||||||
if (addr == 0x25) {
|
if (addr == 0x25) {
|
||||||
int angle_meas_new = ((to_push->RDLR & 0xf) << 8) + ((to_push->RDLR & 0xff00) >> 8);
|
int angle_meas_new = ((GET_BYTE(to_push, 0) & 0xF) << 8) | GET_BYTE(to_push, 1);
|
||||||
uint32_t ts = TIM2->CNT;
|
uint32_t ts = TIM2->CNT;
|
||||||
|
|
||||||
angle_meas_new = to_signed(angle_meas_new, 12);
|
angle_meas_new = to_signed(angle_meas_new, 12);
|
||||||
@@ -81,12 +81,12 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||||||
|
|
||||||
// get speed
|
// get speed
|
||||||
if (addr == 0xb4) {
|
if (addr == 0xb4) {
|
||||||
speed = ((float) (((to_push->RDHR) & 0xFF00) | ((to_push->RDHR >> 16) & 0xFF))) * 0.01 / 3.6;
|
speed = ((float)((GET_BYTE(to_push, 5) << 8) | GET_BYTE(to_push, 6))) * 0.01 / 3.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get ipas state
|
// get ipas state
|
||||||
if (addr == 0x262) {
|
if (addr == 0x262) {
|
||||||
ipas_state = (to_push->RDLR & 0xf);
|
ipas_state = GET_BYTE(to_push, 0) & 0xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit controls on high steering override
|
// exit controls on high steering override
|
||||||
@@ -111,8 +111,8 @@ static int toyota_ipas_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||||||
if ((addr == 0x266) || (addr == 0x167)) {
|
if ((addr == 0x266) || (addr == 0x167)) {
|
||||||
|
|
||||||
angle_control = 1; // we are in angle control mode
|
angle_control = 1; // we are in angle control mode
|
||||||
int desired_angle = ((to_send->RDLR & 0xf) << 8) + ((to_send->RDLR & 0xff00) >> 8);
|
int desired_angle = ((GET_BYTE(to_send, 0) & 0xF) << 8) | GET_BYTE(to_send, 1);
|
||||||
int ipas_state_cmd = ((to_send->RDLR & 0xff) >> 4);
|
int ipas_state_cmd = GET_BYTE(to_send, 0) >> 4;
|
||||||
bool violation = 0;
|
bool violation = 0;
|
||||||
|
|
||||||
desired_angle = to_signed(desired_angle, 12);
|
desired_angle = to_signed(desired_angle, 12);
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF)
|
|
||||||
#define GET_LEN(msg) ((msg)->RDTR & 0xf)
|
|
||||||
#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21))
|
|
||||||
|
|
||||||
// sample struct that keeps 3 samples in memory
|
// sample struct that keeps 3 samples in memory
|
||||||
struct sample_t {
|
struct sample_t {
|
||||||
int values[6];
|
int values[6];
|
||||||
@@ -54,3 +50,6 @@ int gas_interceptor_prev = 0;
|
|||||||
|
|
||||||
// This is set by USB command 0xdf
|
// This is set by USB command 0xdf
|
||||||
bool long_controls_allowed = 1;
|
bool long_controls_allowed = 1;
|
||||||
|
|
||||||
|
// avg between 2 tracks
|
||||||
|
#define GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2)
|
||||||
|
|||||||
+31
-19
@@ -31,7 +31,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
FLASH->KEYR = 0xCDEF89AB;
|
FLASH->KEYR = 0xCDEF89AB;
|
||||||
resp[1] = 0xff;
|
resp[1] = 0xff;
|
||||||
}
|
}
|
||||||
set_led(LED_GREEN, 1);
|
current_board->set_led(LED_GREEN, 1);
|
||||||
unlocked = 1;
|
unlocked = 1;
|
||||||
prog_ptr = (uint32_t *)0x8004000;
|
prog_ptr = (uint32_t *)0x8004000;
|
||||||
break;
|
break;
|
||||||
@@ -92,17 +92,27 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||||||
return resp_len;
|
return resp_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { return 0; }
|
int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) {
|
||||||
void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) { }
|
UNUSED(usbdata);
|
||||||
|
UNUSED(len);
|
||||||
|
UNUSED(hardwired);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) {
|
||||||
|
UNUSED(usbdata);
|
||||||
|
UNUSED(len);
|
||||||
|
UNUSED(hardwired);
|
||||||
|
}
|
||||||
|
|
||||||
int is_enumerated = 0;
|
int is_enumerated = 0;
|
||||||
void usb_cb_enumeration_complete() {
|
void usb_cb_enumeration_complete(void) {
|
||||||
puts("USB enumeration complete\n");
|
puts("USB enumeration complete\n");
|
||||||
is_enumerated = 1;
|
is_enumerated = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {
|
void usb_cb_ep2_out(void *usbdata, int len, bool hardwired) {
|
||||||
set_led(LED_RED, 0);
|
UNUSED(hardwired);
|
||||||
|
current_board->set_led(LED_RED, 0);
|
||||||
for (int i = 0; i < len/4; i++) {
|
for (int i = 0; i < len/4; i++) {
|
||||||
// program byte 1
|
// program byte 1
|
||||||
FLASH->CR = FLASH_CR_PSIZE_1 | FLASH_CR_PG;
|
FLASH->CR = FLASH_CR_PSIZE_1 | FLASH_CR_PG;
|
||||||
@@ -113,11 +123,12 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {
|
|||||||
//*(uint64_t*)(&spi_tx_buf[0x30+(i*4)]) = *prog_ptr;
|
//*(uint64_t*)(&spi_tx_buf[0x30+(i*4)]) = *prog_ptr;
|
||||||
prog_ptr++;
|
prog_ptr++;
|
||||||
}
|
}
|
||||||
set_led(LED_RED, 1);
|
current_board->set_led(LED_RED, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
||||||
|
UNUSED(len);
|
||||||
int resp_len = 0;
|
int resp_len = 0;
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -140,7 +151,7 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
|||||||
#define CAN_BL_INPUT 0x1
|
#define CAN_BL_INPUT 0x1
|
||||||
#define CAN_BL_OUTPUT 0x2
|
#define CAN_BL_OUTPUT 0x2
|
||||||
|
|
||||||
void CAN1_TX_IRQHandler() {
|
void CAN1_TX_IRQHandler(void) {
|
||||||
// clear interrupt
|
// clear interrupt
|
||||||
CAN->TSR |= CAN_TSR_RQCP0;
|
CAN->TSR |= CAN_TSR_RQCP0;
|
||||||
}
|
}
|
||||||
@@ -167,12 +178,13 @@ void bl_can_send(uint8_t *odat) {
|
|||||||
CAN->sTxMailBox[0].TIR = (CAN_BL_OUTPUT << 21) | 1;
|
CAN->sTxMailBox[0].TIR = (CAN_BL_OUTPUT << 21) | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAN1_RX0_IRQHandler() {
|
void CAN1_RX0_IRQHandler(void) {
|
||||||
while (CAN->RF0R & CAN_RF0R_FMP0) {
|
while (CAN->RF0R & CAN_RF0R_FMP0) {
|
||||||
if ((CAN->sFIFOMailBox[0].RIR>>21) == CAN_BL_INPUT) {
|
if ((CAN->sFIFOMailBox[0].RIR>>21) == CAN_BL_INPUT) {
|
||||||
uint8_t dat[8];
|
uint8_t dat[8];
|
||||||
((uint32_t*)dat)[0] = CAN->sFIFOMailBox[0].RDLR;
|
for (int i = 0; i < 8; i++) {
|
||||||
((uint32_t*)dat)[1] = CAN->sFIFOMailBox[0].RDHR;
|
dat[0] = GET_BYTE(&CAN->sFIFOMailBox[0], i);
|
||||||
|
}
|
||||||
uint8_t odat[8];
|
uint8_t odat[8];
|
||||||
uint8_t type = dat[0] & 0xF0;
|
uint8_t type = dat[0] & 0xF0;
|
||||||
if (type == 0x30) {
|
if (type == 0x30) {
|
||||||
@@ -241,13 +253,13 @@ void CAN1_RX0_IRQHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAN1_SCE_IRQHandler() {
|
void CAN1_SCE_IRQHandler(void) {
|
||||||
llcan_clear_send(CAN);
|
llcan_clear_send(CAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void soft_flasher_start() {
|
void soft_flasher_start(void) {
|
||||||
puts("\n\n\n************************ FLASHER START ************************\n");
|
puts("\n\n\n************************ FLASHER START ************************\n");
|
||||||
|
|
||||||
enter_bootloader_mode = 0;
|
enter_bootloader_mode = 0;
|
||||||
@@ -264,7 +276,7 @@ void soft_flasher_start() {
|
|||||||
// B8,B9: CAN 1
|
// B8,B9: CAN 1
|
||||||
set_gpio_alternate(GPIOB, 8, GPIO_AF9_CAN1);
|
set_gpio_alternate(GPIOB, 8, GPIO_AF9_CAN1);
|
||||||
set_gpio_alternate(GPIOB, 9, GPIO_AF9_CAN1);
|
set_gpio_alternate(GPIOB, 9, GPIO_AF9_CAN1);
|
||||||
set_can_enable(CAN1, 1);
|
current_board->enable_can_transciever(1, true);
|
||||||
|
|
||||||
// init can
|
// init can
|
||||||
llcan_set_speed(CAN1, 5000, false, false);
|
llcan_set_speed(CAN1, 5000, false, false);
|
||||||
@@ -293,7 +305,7 @@ void soft_flasher_start() {
|
|||||||
usb_init();
|
usb_init();
|
||||||
|
|
||||||
// green LED on for flashing
|
// green LED on for flashing
|
||||||
set_led(LED_GREEN, 1);
|
current_board->set_led(LED_GREEN, 1);
|
||||||
|
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
@@ -304,13 +316,13 @@ void soft_flasher_start() {
|
|||||||
// if you are connected through a hub to the phone
|
// if you are connected through a hub to the phone
|
||||||
// you need power to be able to see the device
|
// you need power to be able to see the device
|
||||||
puts("USBP: didn't enumerate, switching to CDP mode\n");
|
puts("USBP: didn't enumerate, switching to CDP mode\n");
|
||||||
set_usb_power_mode(USB_POWER_CDP);
|
current_board->set_usb_power_mode(USB_POWER_CDP);
|
||||||
set_led(LED_BLUE, 1);
|
current_board->set_led(LED_BLUE, 1);
|
||||||
}
|
}
|
||||||
// blink the green LED fast
|
// blink the green LED fast
|
||||||
set_led(LED_GREEN, 0);
|
current_board->set_led(LED_GREEN, 0);
|
||||||
delay(500000);
|
delay(500000);
|
||||||
set_led(LED_GREEN, 1);
|
current_board->set_led(LED_GREEN, 1);
|
||||||
delay(500000);
|
delay(500000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-13
@@ -16,7 +16,7 @@ from update import ensure_st_up_to_date
|
|||||||
from serial import PandaSerial
|
from serial import PandaSerial
|
||||||
from isotp import isotp_send, isotp_recv
|
from isotp import isotp_send, isotp_recv
|
||||||
|
|
||||||
__version__ = '0.0.8'
|
__version__ = '0.0.9'
|
||||||
|
|
||||||
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
|
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
|
||||||
|
|
||||||
@@ -232,10 +232,10 @@ class Panda(object):
|
|||||||
print("flash: unlocking")
|
print("flash: unlocking")
|
||||||
handle.controlWrite(Panda.REQUEST_IN, 0xb1, 0, 0, b'')
|
handle.controlWrite(Panda.REQUEST_IN, 0xb1, 0, 0, b'')
|
||||||
|
|
||||||
# erase sectors 1 and 2
|
# erase sectors 1 through 3
|
||||||
print("flash: erasing")
|
print("flash: erasing")
|
||||||
handle.controlWrite(Panda.REQUEST_IN, 0xb2, 1, 0, b'')
|
for i in range(1, 4):
|
||||||
handle.controlWrite(Panda.REQUEST_IN, 0xb2, 2, 0, b'')
|
handle.controlWrite(Panda.REQUEST_IN, 0xb2, i, 0, b'')
|
||||||
|
|
||||||
# flash over EP2
|
# flash over EP2
|
||||||
STEP = 0x10
|
STEP = 0x10
|
||||||
@@ -334,13 +334,19 @@ class Panda(object):
|
|||||||
# ******************* health *******************
|
# ******************* health *******************
|
||||||
|
|
||||||
def health(self):
|
def health(self):
|
||||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd2, 0, 0, 13)
|
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd2, 0, 0, 24)
|
||||||
a = struct.unpack("IIBBBBB", dat)
|
a = struct.unpack("IIIIIBBBB", dat)
|
||||||
return {"voltage": a[0], "current": a[1],
|
return {
|
||||||
"started": a[2], "controls_allowed": a[3],
|
"voltage": a[0],
|
||||||
"gas_interceptor_detected": a[4],
|
"current": a[1],
|
||||||
"started_signal_detected": a[5],
|
"can_send_errs": a[2],
|
||||||
"started_alt": a[6]}
|
"can_fwd_errs": a[3],
|
||||||
|
"gmlan_send_errs": a[4],
|
||||||
|
"started": a[5],
|
||||||
|
"controls_allowed": a[6],
|
||||||
|
"gas_interceptor_detected": a[7],
|
||||||
|
"car_harness_status": a[8]
|
||||||
|
}
|
||||||
|
|
||||||
# ******************* control *******************
|
# ******************* control *******************
|
||||||
|
|
||||||
@@ -354,9 +360,14 @@ class Panda(object):
|
|||||||
def get_version(self):
|
def get_version(self):
|
||||||
return self._handle.controlRead(Panda.REQUEST_IN, 0xd6, 0, 0, 0x40)
|
return self._handle.controlRead(Panda.REQUEST_IN, 0xd6, 0, 0, 0x40)
|
||||||
|
|
||||||
|
def get_type(self):
|
||||||
|
return self._handle.controlRead(Panda.REQUEST_IN, 0xc1, 0, 0, 0x40)
|
||||||
|
|
||||||
def is_grey(self):
|
def is_grey(self):
|
||||||
ret = self._handle.controlRead(Panda.REQUEST_IN, 0xc1, 0, 0, 0x40)
|
return self.get_type() == "\x02"
|
||||||
return ret == "\x01"
|
|
||||||
|
def is_black(self):
|
||||||
|
return self.get_type() == "\x03"
|
||||||
|
|
||||||
def get_serial(self):
|
def get_serial(self):
|
||||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20)
|
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20)
|
||||||
@@ -387,11 +398,16 @@ class Panda(object):
|
|||||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdd, from_bus, to_bus, b'')
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdd, from_bus, to_bus, b'')
|
||||||
|
|
||||||
def set_gmlan(self, bus=2):
|
def set_gmlan(self, bus=2):
|
||||||
|
# TODO: check panda type
|
||||||
if bus is None:
|
if bus is None:
|
||||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 0, 0, b'')
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 0, 0, b'')
|
||||||
elif bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
elif bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
||||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'')
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'')
|
||||||
|
|
||||||
|
def set_obd(self, obd):
|
||||||
|
# TODO: check panda type
|
||||||
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, int(obd), 0, b'')
|
||||||
|
|
||||||
def set_can_loopback(self, enable):
|
def set_can_loopback(self, enable):
|
||||||
# set can loopback mode for all buses
|
# set can loopback mode for all buses
|
||||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xe5, int(enable), 0, b'')
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xe5, int(enable), 0, b'')
|
||||||
@@ -559,3 +575,6 @@ class Panda(object):
|
|||||||
msg = self.kline_ll_recv(2, bus=bus)
|
msg = self.kline_ll_recv(2, bus=bus)
|
||||||
msg += self.kline_ll_recv(ord(msg[1])-2, bus=bus)
|
msg += self.kline_ll_recv(ord(msg[1])-2, bus=bus)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
def send_heartbeat(self):
|
||||||
|
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf3, 0, 0, b'')
|
||||||
|
|||||||
@@ -1216,7 +1216,7 @@ def main():
|
|||||||
operation_func = globals()[args.operation]
|
operation_func = globals()[args.operation]
|
||||||
operation_args,_,_,_ = inspect.getargspec(operation_func)
|
operation_args,_,_,_ = inspect.getargspec(operation_func)
|
||||||
if operation_args[0] == 'esp': # operation function takes an ESPROM connection object
|
if operation_args[0] == 'esp': # operation function takes an ESPROM connection object
|
||||||
initial_baud = MIN(ESPROM.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate
|
initial_baud = min(ESPROM.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate
|
||||||
esp = ESPROM(args.port, initial_baud)
|
esp = ESPROM(args.port, initial_baud)
|
||||||
esp.connect()
|
esp.connect()
|
||||||
operation_func(esp, args)
|
operation_func(esp, args)
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
TEST_FILENAME=${TEST_FILENAME:-nosetests.xml}
|
TEST_FILENAME=${TEST_FILENAME:-nosetests.xml}
|
||||||
if [ ! -f "/EON" ]; then
|
if [ -f "/EON" ]; then
|
||||||
TESTSUITE_NAME="Panda_Test-EON"
|
TESTSUITE_NAME="Panda_Test-EON"
|
||||||
else
|
else
|
||||||
TESTSUITE_NAME="Panda_Test-DEV"
|
TESTSUITE_NAME="Panda_Test-DEV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd boardesp
|
if [ ! -z "${SKIPWIFI}" ] || [ -f "/EON" ]; then
|
||||||
make flashall
|
TEST_SCRIPTS=$(ls tests/automated/$1*.py | grep -v wifi)
|
||||||
cd ..
|
else
|
||||||
|
TEST_SCRIPTS=$(ls tests/automated/$1*.py)
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
for NAME in $(nmcli --fields NAME con show | grep panda | awk '{$1=$1};1')
|
||||||
|
do
|
||||||
|
nmcli connection delete "$NAME"
|
||||||
|
done
|
||||||
|
|
||||||
PYTHONPATH="." python $(which nosetests) -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s tests/automated/$1*.py
|
PYTHONPATH="." python $(which nosetests) -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s $TEST_SCRIPTS
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ def test_can_loopback(serial=None):
|
|||||||
busses = [0,1,2]
|
busses = [0,1,2]
|
||||||
|
|
||||||
for bus in busses:
|
for bus in busses:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# set bus 0 speed to 250
|
# set bus 0 speed to 250
|
||||||
p.set_can_speed_kbps(bus, 250)
|
p.set_can_speed_kbps(bus, 250)
|
||||||
|
|
||||||
@@ -52,6 +55,9 @@ def test_safety_nooutput(serial=None):
|
|||||||
# enable output mode
|
# enable output mode
|
||||||
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# enable CAN loopback mode
|
# enable CAN loopback mode
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
|
|
||||||
@@ -76,11 +82,17 @@ def test_reliability(serial=None):
|
|||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
p.set_can_speed_kbps(0, 1000)
|
p.set_can_speed_kbps(0, 1000)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
addrs = range(100, 100+MSG_COUNT)
|
addrs = range(100, 100+MSG_COUNT)
|
||||||
ts = [(j, 0, "\xaa"*8, 0) for j in addrs]
|
ts = [(j, 0, "\xaa"*8, 0) for j in addrs]
|
||||||
|
|
||||||
# 100 loops
|
# 100 loops
|
||||||
for i in range(LOOP_COUNT):
|
for i in range(LOOP_COUNT):
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
st = time.time()
|
st = time.time()
|
||||||
|
|
||||||
p.can_send_many(ts)
|
p.can_send_many(ts)
|
||||||
@@ -111,6 +123,9 @@ def test_throughput(serial=None):
|
|||||||
# enable output mode
|
# enable output mode
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# enable CAN loopback mode
|
# enable CAN loopback mode
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
|
|
||||||
@@ -119,6 +134,9 @@ def test_throughput(serial=None):
|
|||||||
p.set_can_speed_kbps(0, speed)
|
p.set_can_speed_kbps(0, speed)
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
comp_kbps = time_many_sends(p, 0)
|
comp_kbps = time_many_sends(p, 0)
|
||||||
|
|
||||||
# bit count from https://en.wikipedia.org/wiki/CAN_bus
|
# bit count from https://en.wikipedia.org/wiki/CAN_bus
|
||||||
@@ -139,6 +157,9 @@ def test_gmlan(serial=None):
|
|||||||
# enable output mode
|
# enable output mode
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# enable CAN loopback mode
|
# enable CAN loopback mode
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
|
|
||||||
@@ -148,6 +169,9 @@ def test_gmlan(serial=None):
|
|||||||
|
|
||||||
# set gmlan on CAN2
|
# set gmlan on CAN2
|
||||||
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3, Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3, Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
p.set_gmlan(bus)
|
p.set_gmlan(bus)
|
||||||
comp_kbps_gmlan = time_many_sends(p, 3)
|
comp_kbps_gmlan = time_many_sends(p, 3)
|
||||||
assert_greater(comp_kbps_gmlan, 0.8 * SPEED_GMLAN)
|
assert_greater(comp_kbps_gmlan, 0.8 * SPEED_GMLAN)
|
||||||
@@ -171,11 +195,17 @@ def test_gmlan_bad_toggle(serial=None):
|
|||||||
# enable output mode
|
# enable output mode
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# enable CAN loopback mode
|
# enable CAN loopback mode
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
|
|
||||||
# GMLAN_CAN2
|
# GMLAN_CAN2
|
||||||
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
p.set_gmlan(bus)
|
p.set_gmlan(bus)
|
||||||
comp_kbps_gmlan = time_many_sends(p, 3)
|
comp_kbps_gmlan = time_many_sends(p, 3)
|
||||||
assert_greater(comp_kbps_gmlan, 0.6 * SPEED_GMLAN)
|
assert_greater(comp_kbps_gmlan, 0.6 * SPEED_GMLAN)
|
||||||
@@ -183,6 +213,9 @@ def test_gmlan_bad_toggle(serial=None):
|
|||||||
|
|
||||||
# normal
|
# normal
|
||||||
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
p.set_gmlan(None)
|
p.set_gmlan(None)
|
||||||
comp_kbps_normal = time_many_sends(p, bus)
|
comp_kbps_normal = time_many_sends(p, bus)
|
||||||
assert_greater(comp_kbps_normal, 0.6 * SPEED_NORMAL)
|
assert_greater(comp_kbps_normal, 0.6 * SPEED_NORMAL)
|
||||||
|
|||||||
@@ -21,12 +21,18 @@ def test_throughput(serial=None):
|
|||||||
# enable output mode
|
# enable output mode
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# enable CAN loopback mode
|
# enable CAN loopback mode
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
|
|
||||||
p = Panda("WIFI")
|
p = Panda("WIFI")
|
||||||
|
|
||||||
for speed in [100,250,500,750,1000]:
|
for speed in [100,250,500,750,1000]:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
# set bus 0 speed to speed
|
# set bus 0 speed to speed
|
||||||
p.set_can_speed_kbps(0, speed)
|
p.set_can_speed_kbps(0, speed)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@@ -46,11 +52,18 @@ def test_recv_only(serial=None):
|
|||||||
connect_wifi(serial)
|
connect_wifi(serial)
|
||||||
p = Panda(serial)
|
p = Panda(serial)
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
p.set_can_loopback(True)
|
p.set_can_loopback(True)
|
||||||
pwifi = Panda("WIFI")
|
pwifi = Panda("WIFI")
|
||||||
|
|
||||||
# TODO: msg_count=1000 drops packets, is this fixable?
|
# TODO: msg_count=1000 drops packets, is this fixable?
|
||||||
for msg_count in [10,100,200]:
|
for msg_count in [10,100,200]:
|
||||||
|
# send heartbeat
|
||||||
|
p.send_heartbeat()
|
||||||
|
|
||||||
speed = 500
|
speed = 500
|
||||||
p.set_can_speed_kbps(0, speed)
|
p.set_can_speed_kbps(0, speed)
|
||||||
comp_kbps = time_many_sends(p, 0, pwifi, msg_count)
|
comp_kbps = time_many_sends(p, 0, pwifi, msg_count)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def test_udp_doesnt_drop(serial=None):
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
else:
|
else:
|
||||||
print("UDP WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct))
|
print("UDP WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct))
|
||||||
assert_greater(saturation_pct, 15) #sometimes the wifi can be slow...
|
assert_greater(saturation_pct, 20) #sometimes the wifi can be slow...
|
||||||
assert_less(saturation_pct, 100)
|
assert_less(saturation_pct, 100)
|
||||||
saturation_pcts.append(saturation_pct)
|
saturation_pcts.append(saturation_pct)
|
||||||
if len(saturation_pcts) > 0:
|
if len(saturation_pcts) > 0:
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ def test_send_recv(serial_sender=None, serial_reciever=None):
|
|||||||
p_send.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p_send.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
p_send.set_can_loopback(False)
|
p_send.set_can_loopback(False)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p_send.send_heartbeat()
|
||||||
|
|
||||||
p_recv.set_can_loopback(False)
|
p_recv.set_can_loopback(False)
|
||||||
|
|
||||||
assert not p_send.legacy
|
assert not p_send.legacy
|
||||||
@@ -27,6 +30,9 @@ def test_send_recv(serial_sender=None, serial_reciever=None):
|
|||||||
|
|
||||||
for bus in busses:
|
for bus in busses:
|
||||||
for speed in [100, 250, 500, 750, 1000]:
|
for speed in [100, 250, 500, 750, 1000]:
|
||||||
|
# send heartbeat
|
||||||
|
p_send.send_heartbeat()
|
||||||
|
|
||||||
p_send.set_can_speed_kbps(bus, speed)
|
p_send.set_can_speed_kbps(bus, speed)
|
||||||
p_recv.set_can_speed_kbps(bus, speed)
|
p_recv.set_can_speed_kbps(bus, speed)
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
@@ -45,6 +51,10 @@ def test_latency(serial_sender=None, serial_reciever=None):
|
|||||||
p_send = Panda(serial_sender)
|
p_send = Panda(serial_sender)
|
||||||
p_recv = Panda(serial_reciever)
|
p_recv = Panda(serial_reciever)
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p_send.send_heartbeat()
|
||||||
|
p_recv.send_heartbeat()
|
||||||
|
|
||||||
p_send.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p_send.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
p_send.set_can_loopback(False)
|
p_send.set_can_loopback(False)
|
||||||
|
|
||||||
@@ -62,10 +72,18 @@ def test_latency(serial_sender=None, serial_reciever=None):
|
|||||||
p_recv.can_recv()
|
p_recv.can_recv()
|
||||||
p_send.can_recv()
|
p_send.can_recv()
|
||||||
|
|
||||||
|
# send heartbeat
|
||||||
|
p_send.send_heartbeat()
|
||||||
|
p_recv.send_heartbeat()
|
||||||
|
|
||||||
busses = [0,1,2]
|
busses = [0,1,2]
|
||||||
|
|
||||||
for bus in busses:
|
for bus in busses:
|
||||||
for speed in [100, 250, 500, 750, 1000]:
|
for speed in [100, 250, 500, 750, 1000]:
|
||||||
|
# send heartbeat
|
||||||
|
p_send.send_heartbeat()
|
||||||
|
p_recv.send_heartbeat()
|
||||||
|
|
||||||
p_send.set_can_speed_kbps(bus, speed)
|
p_send.set_can_speed_kbps(bus, speed)
|
||||||
p_recv.set_can_speed_kbps(bus, speed)
|
p_recv.set_can_speed_kbps(bus, speed)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|||||||
Executable
+139
@@ -0,0 +1,139 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Loopback test between black panda (+ harness and power) and white/grey panda
|
||||||
|
# Tests all buses, including OBD CAN, which is on the same bus as CAN0 in this test.
|
||||||
|
# To be sure, the test should be run with both harness orientations
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
from hexdump import hexdump
|
||||||
|
from itertools import permutations
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
|
||||||
|
from panda import Panda
|
||||||
|
|
||||||
|
def get_test_string():
|
||||||
|
return b"test"+os.urandom(10)
|
||||||
|
|
||||||
|
def run_test(sleep_duration):
|
||||||
|
pandas = Panda.list()
|
||||||
|
print(pandas)
|
||||||
|
|
||||||
|
# make sure two pandas are connected
|
||||||
|
if len(pandas) != 2:
|
||||||
|
print("Connect white/grey and black panda to run this test!")
|
||||||
|
assert False
|
||||||
|
|
||||||
|
# connect
|
||||||
|
pandas[0] = Panda(pandas[0])
|
||||||
|
pandas[1] = Panda(pandas[1])
|
||||||
|
|
||||||
|
# find out which one is black
|
||||||
|
type0 = pandas[0].get_type()
|
||||||
|
type1 = pandas[1].get_type()
|
||||||
|
|
||||||
|
black_panda = None
|
||||||
|
other_panda = None
|
||||||
|
|
||||||
|
if type0 == "\x03" and type1 != "\x03":
|
||||||
|
black_panda = pandas[0]
|
||||||
|
other_panda = pandas[1]
|
||||||
|
elif type0 != "\x03" and type1 == "\x03":
|
||||||
|
black_panda = pandas[1]
|
||||||
|
other_panda = pandas[0]
|
||||||
|
else:
|
||||||
|
print("Connect white/grey and black panda to run this test!")
|
||||||
|
assert False
|
||||||
|
|
||||||
|
# disable safety modes
|
||||||
|
black_panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
other_panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
|
# test health packet
|
||||||
|
print("black panda health", black_panda.health())
|
||||||
|
print("other panda health", other_panda.health())
|
||||||
|
|
||||||
|
# test black -> other
|
||||||
|
test_buses(black_panda, other_panda, True, [(0, False, [0]), (1, False, [1]), (2, False, [2]), (1, True, [0])], sleep_duration)
|
||||||
|
test_buses(black_panda, other_panda, False, [(0, False, [0]), (1, False, [1]), (2, False, [2]), (0, True, [0, 1])], sleep_duration)
|
||||||
|
|
||||||
|
|
||||||
|
def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):
|
||||||
|
if direction:
|
||||||
|
print("***************** TESTING (BLACK --> OTHER) *****************")
|
||||||
|
else:
|
||||||
|
print("***************** TESTING (OTHER --> BLACK) *****************")
|
||||||
|
|
||||||
|
for send_bus, obd, recv_buses in test_array:
|
||||||
|
black_panda.send_heartbeat()
|
||||||
|
other_panda.send_heartbeat()
|
||||||
|
print("\ntest can: ", send_bus, " OBD: ", obd)
|
||||||
|
|
||||||
|
# set OBD on black panda
|
||||||
|
black_panda.set_gmlan(True if obd else None)
|
||||||
|
|
||||||
|
# clear and flush
|
||||||
|
if direction:
|
||||||
|
black_panda.can_clear(send_bus)
|
||||||
|
else:
|
||||||
|
other_panda.can_clear(send_bus)
|
||||||
|
|
||||||
|
for recv_bus in recv_buses:
|
||||||
|
if direction:
|
||||||
|
other_panda.can_clear(recv_bus)
|
||||||
|
else:
|
||||||
|
black_panda.can_clear(recv_bus)
|
||||||
|
|
||||||
|
black_panda.can_recv()
|
||||||
|
other_panda.can_recv()
|
||||||
|
|
||||||
|
# send the characters
|
||||||
|
at = random.randint(1, 2000)
|
||||||
|
st = get_test_string()[0:8]
|
||||||
|
if direction:
|
||||||
|
black_panda.can_send(at, st, send_bus)
|
||||||
|
else:
|
||||||
|
other_panda.can_send(at, st, send_bus)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# check for receive
|
||||||
|
if direction:
|
||||||
|
cans_echo = black_panda.can_recv()
|
||||||
|
cans_loop = other_panda.can_recv()
|
||||||
|
else:
|
||||||
|
cans_echo = other_panda.can_recv()
|
||||||
|
cans_loop = black_panda.can_recv()
|
||||||
|
|
||||||
|
loop_buses = []
|
||||||
|
for loop in cans_loop:
|
||||||
|
print(" Loop on bus", str(loop[3]))
|
||||||
|
loop_buses.append(loop[3])
|
||||||
|
if len(cans_loop) == 0:
|
||||||
|
print(" No loop")
|
||||||
|
|
||||||
|
# test loop buses
|
||||||
|
recv_buses.sort()
|
||||||
|
loop_buses.sort()
|
||||||
|
assert recv_buses == loop_buses
|
||||||
|
print(" TEST PASSED")
|
||||||
|
|
||||||
|
time.sleep(sleep_duration)
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-n", type=int, help="Number of test iterations to run")
|
||||||
|
parser.add_argument("-sleep", type=int, help="Sleep time between tests", default=0)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.n is None:
|
||||||
|
while True:
|
||||||
|
run_test(sleep_duration=args.sleep)
|
||||||
|
else:
|
||||||
|
for i in range(args.n):
|
||||||
|
run_test(sleep_duration=args.sleep)
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
FROM ubuntu:16.04
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi python python-pip gcc g++
|
|
||||||
|
|
||||||
RUN pip install pycrypto==2.6.1
|
|
||||||
|
|
||||||
COPY . /panda
|
|
||||||
|
|
||||||
WORKDIR /panda
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
cd ../../board/
|
|
||||||
|
|
||||||
make -f Makefile.strict clean
|
|
||||||
make -f Makefile.strict bin 2> compiler_output.txt
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -s "compiler_output.txt" ]]
|
|
||||||
then
|
|
||||||
echo "Found alerts from the compiler:"
|
|
||||||
cat compiler_output.txt
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class ELMCarSimulator():
|
|||||||
if len(outmsg) <= 5:
|
if len(outmsg) <= 5:
|
||||||
self._lin_send(0x10, obd_header + outmsg)
|
self._lin_send(0x10, obd_header + outmsg)
|
||||||
else:
|
else:
|
||||||
first_msg_len = MIN(4, len(outmsg)%4) or 4
|
first_msg_len = min(4, len(outmsg)%4) or 4
|
||||||
self._lin_send(0x10, obd_header + b'\x01' +
|
self._lin_send(0x10, obd_header + b'\x01' +
|
||||||
b'\x00'*(4-first_msg_len) +
|
b'\x00'*(4-first_msg_len) +
|
||||||
outmsg[:first_msg_len])
|
outmsg[:first_msg_len])
|
||||||
@@ -229,7 +229,7 @@ class ELMCarSimulator():
|
|||||||
outaddr = 0x7E8 if address == 0x7DF or address == 0x7E0 else 0x18DAF110
|
outaddr = 0x7E8 if address == 0x7DF or address == 0x7E0 else 0x18DAF110
|
||||||
msgnum = 1
|
msgnum = 1
|
||||||
while(self.__can_multipart_data):
|
while(self.__can_multipart_data):
|
||||||
datalen = MIN(7, len(self.__can_multipart_data))
|
datalen = min(7, len(self.__can_multipart_data))
|
||||||
msgpiece = struct.pack("B", 0x20 | msgnum) + self.__can_multipart_data[:datalen]
|
msgpiece = struct.pack("B", 0x20 | msgnum) + self.__can_multipart_data[:datalen]
|
||||||
self._can_send(outaddr, msgpiece)
|
self._can_send(outaddr, msgpiece)
|
||||||
self.__can_multipart_data = self.__can_multipart_data[7:]
|
self.__can_multipart_data = self.__can_multipart_data[7:]
|
||||||
@@ -246,7 +246,7 @@ class ELMCarSimulator():
|
|||||||
self._can_send(outaddr,
|
self._can_send(outaddr,
|
||||||
struct.pack("BBB", len(outmsg)+2, 0x40|data[1], pid) + outmsg)
|
struct.pack("BBB", len(outmsg)+2, 0x40|data[1], pid) + outmsg)
|
||||||
else:
|
else:
|
||||||
first_msg_len = MIN(3, len(outmsg)%7)
|
first_msg_len = min(3, len(outmsg)%7)
|
||||||
payload_len = len(outmsg)+3
|
payload_len = len(outmsg)+3
|
||||||
msgpiece = struct.pack("BBBBB", 0x10 | ((payload_len>>8)&0xF),
|
msgpiece = struct.pack("BBBBB", 0x10 | ((payload_len>>8)&0xF),
|
||||||
payload_len&0xFF,
|
payload_len&0xFF,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from panda import Panda
|
|||||||
p = Panda()
|
p = Panda()
|
||||||
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||||
|
|
||||||
# ack any crap on bus
|
# hack anything on bus
|
||||||
p.set_gmlan(bus=2)
|
p.set_gmlan(bus=2)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
while len(p.can_recv()) > 0:
|
while len(p.can_recv()) > 0:
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
FROM ubuntu:16.04
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y make python python-pip
|
||||||
|
COPY tests/safety/requirements.txt /panda/tests/safety/requirements.txt
|
||||||
|
RUN pip install -r /panda/tests/safety/requirements.txt
|
||||||
|
COPY . /panda
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1,451 @@
|
|||||||
|
4r5e
|
||||||
|
5h1t
|
||||||
|
5hit
|
||||||
|
a55
|
||||||
|
anal
|
||||||
|
anus
|
||||||
|
ar5e
|
||||||
|
arrse
|
||||||
|
arse
|
||||||
|
ass
|
||||||
|
ass-fucker
|
||||||
|
asses
|
||||||
|
assfucker
|
||||||
|
assfukka
|
||||||
|
asshole
|
||||||
|
assholes
|
||||||
|
asswhole
|
||||||
|
a_s_s
|
||||||
|
b!tch
|
||||||
|
b00bs
|
||||||
|
b17ch
|
||||||
|
b1tch
|
||||||
|
ballbag
|
||||||
|
balls
|
||||||
|
ballsack
|
||||||
|
bastard
|
||||||
|
beastial
|
||||||
|
beastiality
|
||||||
|
bellend
|
||||||
|
bestial
|
||||||
|
bestiality
|
||||||
|
bi+ch
|
||||||
|
biatch
|
||||||
|
bitch
|
||||||
|
bitcher
|
||||||
|
bitchers
|
||||||
|
bitches
|
||||||
|
bitchin
|
||||||
|
bitching
|
||||||
|
bloody
|
||||||
|
blow job
|
||||||
|
blowjob
|
||||||
|
blowjobs
|
||||||
|
boiolas
|
||||||
|
bollock
|
||||||
|
bollok
|
||||||
|
boner
|
||||||
|
boob
|
||||||
|
boobs
|
||||||
|
booobs
|
||||||
|
boooobs
|
||||||
|
booooobs
|
||||||
|
booooooobs
|
||||||
|
breasts
|
||||||
|
buceta
|
||||||
|
bugger
|
||||||
|
bum
|
||||||
|
bunny fucker
|
||||||
|
bullshit
|
||||||
|
butt
|
||||||
|
butthole
|
||||||
|
buttmuch
|
||||||
|
buttplug
|
||||||
|
c0ck
|
||||||
|
c0cksucker
|
||||||
|
carpet muncher
|
||||||
|
cawk
|
||||||
|
chink
|
||||||
|
cipa
|
||||||
|
cl1t
|
||||||
|
clit
|
||||||
|
clitoris
|
||||||
|
clits
|
||||||
|
cnut
|
||||||
|
cock
|
||||||
|
cock-sucker
|
||||||
|
cockface
|
||||||
|
cockhead
|
||||||
|
cockmunch
|
||||||
|
cockmuncher
|
||||||
|
cocks
|
||||||
|
cocksuck
|
||||||
|
cocksucked
|
||||||
|
cocksucker
|
||||||
|
cocksucking
|
||||||
|
cocksucks
|
||||||
|
cocksuka
|
||||||
|
cocksukka
|
||||||
|
cok
|
||||||
|
cokmuncher
|
||||||
|
coksucka
|
||||||
|
coon
|
||||||
|
cox
|
||||||
|
crap
|
||||||
|
cum
|
||||||
|
cummer
|
||||||
|
cumming
|
||||||
|
cums
|
||||||
|
cumshot
|
||||||
|
cunilingus
|
||||||
|
cunillingus
|
||||||
|
cunnilingus
|
||||||
|
cunt
|
||||||
|
cuntlick
|
||||||
|
cuntlicker
|
||||||
|
cuntlicking
|
||||||
|
cunts
|
||||||
|
cyalis
|
||||||
|
cyberfuc
|
||||||
|
cyberfuck
|
||||||
|
cyberfucked
|
||||||
|
cyberfucker
|
||||||
|
cyberfuckers
|
||||||
|
cyberfucking
|
||||||
|
d1ck
|
||||||
|
damn
|
||||||
|
dick
|
||||||
|
dickhead
|
||||||
|
dildo
|
||||||
|
dildos
|
||||||
|
dink
|
||||||
|
dinks
|
||||||
|
dirsa
|
||||||
|
dlck
|
||||||
|
dog-fucker
|
||||||
|
doggin
|
||||||
|
dogging
|
||||||
|
donkeyribber
|
||||||
|
doosh
|
||||||
|
duche
|
||||||
|
dyke
|
||||||
|
ejaculate
|
||||||
|
ejaculated
|
||||||
|
ejaculates
|
||||||
|
ejaculating
|
||||||
|
ejaculatings
|
||||||
|
ejaculation
|
||||||
|
ejakulate
|
||||||
|
f u c k
|
||||||
|
f u c k e r
|
||||||
|
f4nny
|
||||||
|
fag
|
||||||
|
fagging
|
||||||
|
faggitt
|
||||||
|
faggot
|
||||||
|
faggs
|
||||||
|
fagot
|
||||||
|
fagots
|
||||||
|
fags
|
||||||
|
fanny
|
||||||
|
fannyflaps
|
||||||
|
fannyfucker
|
||||||
|
fanyy
|
||||||
|
fatass
|
||||||
|
fcuk
|
||||||
|
fcuker
|
||||||
|
fcuking
|
||||||
|
feck
|
||||||
|
fecker
|
||||||
|
felching
|
||||||
|
fellate
|
||||||
|
fellatio
|
||||||
|
fingerfuck
|
||||||
|
fingerfucked
|
||||||
|
fingerfucker
|
||||||
|
fingerfuckers
|
||||||
|
fingerfucking
|
||||||
|
fingerfucks
|
||||||
|
fistfuck
|
||||||
|
fistfucked
|
||||||
|
fistfucker
|
||||||
|
fistfuckers
|
||||||
|
fistfucking
|
||||||
|
fistfuckings
|
||||||
|
fistfucks
|
||||||
|
flange
|
||||||
|
fook
|
||||||
|
fooker
|
||||||
|
fuck
|
||||||
|
fucka
|
||||||
|
fucked
|
||||||
|
fucker
|
||||||
|
fuckers
|
||||||
|
fuckhead
|
||||||
|
fuckheads
|
||||||
|
fuckin
|
||||||
|
fucking
|
||||||
|
fuckings
|
||||||
|
fuckingshitmotherfucker
|
||||||
|
fuckme
|
||||||
|
fucks
|
||||||
|
fuckwhit
|
||||||
|
fuckwit
|
||||||
|
fudge packer
|
||||||
|
fudgepacker
|
||||||
|
fuk
|
||||||
|
fuker
|
||||||
|
fukker
|
||||||
|
fukkin
|
||||||
|
fuks
|
||||||
|
fukwhit
|
||||||
|
fukwit
|
||||||
|
fux
|
||||||
|
fux0r
|
||||||
|
f_u_c_k
|
||||||
|
gangbang
|
||||||
|
gangbanged
|
||||||
|
gangbangs
|
||||||
|
gaylord
|
||||||
|
gaysex
|
||||||
|
goatse
|
||||||
|
God
|
||||||
|
god-dam
|
||||||
|
god-damned
|
||||||
|
goddamn
|
||||||
|
goddamned
|
||||||
|
hardcoresex
|
||||||
|
hell
|
||||||
|
heshe
|
||||||
|
hoar
|
||||||
|
hoare
|
||||||
|
hoer
|
||||||
|
homo
|
||||||
|
hore
|
||||||
|
horniest
|
||||||
|
horny
|
||||||
|
hotsex
|
||||||
|
jack-off
|
||||||
|
jackoff
|
||||||
|
jap
|
||||||
|
jerk-off
|
||||||
|
jism
|
||||||
|
jiz
|
||||||
|
jizm
|
||||||
|
jizz
|
||||||
|
kawk
|
||||||
|
knob
|
||||||
|
knobead
|
||||||
|
knobed
|
||||||
|
knobend
|
||||||
|
knobhead
|
||||||
|
knobjocky
|
||||||
|
knobjokey
|
||||||
|
kock
|
||||||
|
kondum
|
||||||
|
kondums
|
||||||
|
kum
|
||||||
|
kummer
|
||||||
|
kumming
|
||||||
|
kums
|
||||||
|
kunilingus
|
||||||
|
l3i+ch
|
||||||
|
l3itch
|
||||||
|
labia
|
||||||
|
lmfao
|
||||||
|
lust
|
||||||
|
lusting
|
||||||
|
m0f0
|
||||||
|
m0fo
|
||||||
|
m45terbate
|
||||||
|
ma5terb8
|
||||||
|
ma5terbate
|
||||||
|
masochist
|
||||||
|
master-bate
|
||||||
|
masterb8
|
||||||
|
masterbat*
|
||||||
|
masterbat3
|
||||||
|
masterbate
|
||||||
|
masterbation
|
||||||
|
masterbations
|
||||||
|
masturbate
|
||||||
|
mo-fo
|
||||||
|
mof0
|
||||||
|
mofo
|
||||||
|
mothafuck
|
||||||
|
mothafucka
|
||||||
|
mothafuckas
|
||||||
|
mothafuckaz
|
||||||
|
mothafucked
|
||||||
|
mothafucker
|
||||||
|
mothafuckers
|
||||||
|
mothafuckin
|
||||||
|
mothafucking
|
||||||
|
mothafuckings
|
||||||
|
mothafucks
|
||||||
|
mother fucker
|
||||||
|
motherfuck
|
||||||
|
motherfucked
|
||||||
|
motherfucker
|
||||||
|
motherfuckers
|
||||||
|
motherfuckin
|
||||||
|
motherfucking
|
||||||
|
motherfuckings
|
||||||
|
motherfuckka
|
||||||
|
motherfucks
|
||||||
|
muff
|
||||||
|
mutha
|
||||||
|
muthafecker
|
||||||
|
muthafuckker
|
||||||
|
muther
|
||||||
|
mutherfucker
|
||||||
|
n1gga
|
||||||
|
n1gger
|
||||||
|
nazi
|
||||||
|
nigg3r
|
||||||
|
nigg4h
|
||||||
|
nigga
|
||||||
|
niggah
|
||||||
|
niggas
|
||||||
|
niggaz
|
||||||
|
nigger
|
||||||
|
niggers
|
||||||
|
nob
|
||||||
|
nob jokey
|
||||||
|
nobhead
|
||||||
|
nobjocky
|
||||||
|
nobjokey
|
||||||
|
numbnuts
|
||||||
|
nutsack
|
||||||
|
orgasim
|
||||||
|
orgasims
|
||||||
|
orgasm
|
||||||
|
orgasms
|
||||||
|
p0rn
|
||||||
|
pawn
|
||||||
|
pecker
|
||||||
|
penis
|
||||||
|
penisfucker
|
||||||
|
phonesex
|
||||||
|
phuck
|
||||||
|
phuk
|
||||||
|
phuked
|
||||||
|
phuking
|
||||||
|
phukked
|
||||||
|
phukking
|
||||||
|
phuks
|
||||||
|
phuq
|
||||||
|
pigfucker
|
||||||
|
pimpis
|
||||||
|
piss
|
||||||
|
pissed
|
||||||
|
pisser
|
||||||
|
pissers
|
||||||
|
pisses
|
||||||
|
pissflaps
|
||||||
|
pissin
|
||||||
|
pissing
|
||||||
|
pissoff
|
||||||
|
poop
|
||||||
|
porn
|
||||||
|
porno
|
||||||
|
pornography
|
||||||
|
pornos
|
||||||
|
prick
|
||||||
|
pricks
|
||||||
|
pron
|
||||||
|
pube
|
||||||
|
pusse
|
||||||
|
pussi
|
||||||
|
pussies
|
||||||
|
pussy
|
||||||
|
pussys
|
||||||
|
rectum
|
||||||
|
retard
|
||||||
|
rimjaw
|
||||||
|
rimming
|
||||||
|
s hit
|
||||||
|
s.o.b.
|
||||||
|
sadist
|
||||||
|
schlong
|
||||||
|
screwing
|
||||||
|
scroat
|
||||||
|
scrote
|
||||||
|
scrotum
|
||||||
|
semen
|
||||||
|
sex
|
||||||
|
sh!+
|
||||||
|
sh!t
|
||||||
|
sh1t
|
||||||
|
shag
|
||||||
|
shagger
|
||||||
|
shaggin
|
||||||
|
shagging
|
||||||
|
shemale
|
||||||
|
shi+
|
||||||
|
shit
|
||||||
|
shitdick
|
||||||
|
shite
|
||||||
|
shited
|
||||||
|
shitey
|
||||||
|
shitfuck
|
||||||
|
shitfull
|
||||||
|
shithead
|
||||||
|
shiting
|
||||||
|
shitings
|
||||||
|
shits
|
||||||
|
shitted
|
||||||
|
shitter
|
||||||
|
shitters
|
||||||
|
shitting
|
||||||
|
shittings
|
||||||
|
shitty
|
||||||
|
skank
|
||||||
|
slut
|
||||||
|
sluts
|
||||||
|
smegma
|
||||||
|
smut
|
||||||
|
snatch
|
||||||
|
son-of-a-bitch
|
||||||
|
spac
|
||||||
|
spunk
|
||||||
|
s_h_i_t
|
||||||
|
t1tt1e5
|
||||||
|
t1tties
|
||||||
|
teets
|
||||||
|
teez
|
||||||
|
testical
|
||||||
|
testicle
|
||||||
|
tit
|
||||||
|
titfuck
|
||||||
|
tits
|
||||||
|
titt
|
||||||
|
tittie5
|
||||||
|
tittiefucker
|
||||||
|
titties
|
||||||
|
tittyfuck
|
||||||
|
tittywank
|
||||||
|
titwank
|
||||||
|
tosser
|
||||||
|
turd
|
||||||
|
tw4t
|
||||||
|
twat
|
||||||
|
twathead
|
||||||
|
twatty
|
||||||
|
twunt
|
||||||
|
twunter
|
||||||
|
v14gra
|
||||||
|
v1gra
|
||||||
|
vagina
|
||||||
|
viagra
|
||||||
|
vulva
|
||||||
|
w00se
|
||||||
|
wang
|
||||||
|
wank
|
||||||
|
wanker
|
||||||
|
wanky
|
||||||
|
whoar
|
||||||
|
whore
|
||||||
|
willies
|
||||||
|
willy
|
||||||
|
xrated
|
||||||
Executable
+28
@@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
checked_ext = ["h", "c", "py", "pyx", "cpp", "hpp", "md", "mk"]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with open("list.txt", 'r') as handle:
|
||||||
|
|
||||||
|
suffix_cmd = " "
|
||||||
|
for i in checked_ext:
|
||||||
|
suffix_cmd += "--include \*." + i + " "
|
||||||
|
|
||||||
|
found_bad_language = False
|
||||||
|
for line in handle:
|
||||||
|
line = line.rstrip('\n').rstrip(" ")
|
||||||
|
try:
|
||||||
|
cmd = "cd ../../; grep -R -i -w " + suffix_cmd + " '" + line + "'"
|
||||||
|
res = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||||
|
print res
|
||||||
|
found_bad_language = True
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
pass
|
||||||
|
if found_bad_language:
|
||||||
|
sys.exit("Failed: found bad language")
|
||||||
|
else:
|
||||||
|
print "Success"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Advisory: union types can be used
|
||||||
|
misra.19.2
|
||||||
|
# FIXME: add it back when fixed in cppcheck. Macro identifiers are unique but it false triggers on defines in #ifdef..#else conditions
|
||||||
|
misra.5.4
|
||||||
|
# Advisory: casting from void pointer to type pointer is ok. Done by STM libraries as well
|
||||||
|
misra.11.4
|
||||||
|
# Advisory: casting from void pointer to type pointer is ok. Done by STM libraries as well
|
||||||
|
misra.11.5
|
||||||
@@ -1,24 +1,53 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
mkdir /tmp/misra || true
|
||||||
git clone https://github.com/danmar/cppcheck.git || true
|
git clone https://github.com/danmar/cppcheck.git || true
|
||||||
cd cppcheck
|
cd cppcheck
|
||||||
git fetch
|
git fetch
|
||||||
git checkout 44d6066c6fad32e2b0332b3f2b24bd340febaef8
|
git checkout 862c4ef87b109ae86c2d5f12769b7c8d199f35c5
|
||||||
make -j4
|
make -j4
|
||||||
cd ../../../
|
cd ../../../
|
||||||
|
|
||||||
# whole panda code
|
|
||||||
tests/misra/cppcheck/cppcheck --dump --enable=all --inline-suppr board/main.c 2>/tmp/misra/cppcheck_output.txt || true
|
|
||||||
python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2>/tmp/misra/misra_output.txt || true
|
|
||||||
|
|
||||||
# violations in safety files
|
printf "\nPANDA CODE\n"
|
||||||
(cat /tmp/misra/misra_output.txt | grep safety) > /tmp/misra/misra_safety_output.txt || true
|
tests/misra/cppcheck/cppcheck -DPANDA -UPEDAL -DCAN3 -DUID_BASE -DEON \
|
||||||
(cat /tmp/misra/cppcheck_output.txt | grep safety) > /tmp/misra/cppcheck_safety_output.txt || true
|
--suppressions-list=tests/misra/suppressions.txt \
|
||||||
|
--dump --enable=all --inline-suppr --force \
|
||||||
|
board/main.c 2>/tmp/misra/cppcheck_output.txt
|
||||||
|
|
||||||
if [[ -s "/tmp/misra/misra_safety_output.txt" ]] || [[ -s "/tmp/misra/cppcheck_safety_output.txt" ]]
|
python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2> /tmp/misra/misra_output.txt || true
|
||||||
|
|
||||||
|
# strip (information) lines
|
||||||
|
cppcheck_output=$( cat /tmp/misra/cppcheck_output.txt | grep -v "(information) " ) || true
|
||||||
|
misra_output=$( cat /tmp/misra/misra_output.txt | grep -v "(information) " ) || true
|
||||||
|
|
||||||
|
|
||||||
|
printf "\nPEDAL CODE\n"
|
||||||
|
tests/misra/cppcheck/cppcheck -UPANDA -DPEDAL -UCAN3 \
|
||||||
|
--suppressions-list=tests/misra/suppressions.txt \
|
||||||
|
-I board/ --dump --enable=all --inline-suppr --force \
|
||||||
|
board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt
|
||||||
|
|
||||||
|
python tests/misra/cppcheck/addons/misra.py board/pedal/main.c.dump 2> /tmp/misra/misra_pedal_output.txt || true
|
||||||
|
|
||||||
|
# strip (information) lines
|
||||||
|
cppcheck_pedal_output=$( cat /tmp/misra/cppcheck_pedal_output.txt | grep -v "(information) " ) || true
|
||||||
|
misra_pedal_output=$( cat /tmp/misra/misra_pedal_output.txt | grep -v "(information) " ) || true
|
||||||
|
|
||||||
|
if [[ -n "$misra_output" ]] || [[ -n "$cppcheck_output" ]]
|
||||||
then
|
then
|
||||||
echo "Found Misra violations in the safety code:"
|
echo "Failed! found Misra violations in panda code:"
|
||||||
cat /tmp/misra/misra_safety_output.txt
|
echo "$misra_output"
|
||||||
cat /tmp/misra/cppcheck_safety_output.txt
|
echo "$cppcheck_output"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$misra_pedal_output" ]] || [[ -n "$cppcheck_pedal_output" ]]
|
||||||
|
then
|
||||||
|
echo "Failed! found Misra violations in pedal code:"
|
||||||
|
echo "$misra_pedal_output"
|
||||||
|
echo "$cppcheck_pedal_output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Success"
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ bool get_long_controls_allowed(void);
|
|||||||
void set_gas_interceptor_detected(bool c);
|
void set_gas_interceptor_detected(bool c);
|
||||||
bool get_gas_interceptor_detetcted(void);
|
bool get_gas_interceptor_detetcted(void);
|
||||||
int get_gas_interceptor_prev(void);
|
int get_gas_interceptor_prev(void);
|
||||||
|
int get_hw_type(void);
|
||||||
void set_timer(uint32_t t);
|
void set_timer(uint32_t t);
|
||||||
void reset_angle_control(void);
|
void reset_angle_control(void);
|
||||||
|
|
||||||
@@ -55,11 +56,12 @@ void set_toyota_camera_forwarded(int t);
|
|||||||
void set_toyota_rt_torque_last(int t);
|
void set_toyota_rt_torque_last(int t);
|
||||||
|
|
||||||
void init_tests_honda(void);
|
void init_tests_honda(void);
|
||||||
int get_honda_ego_speed(void);
|
bool get_honda_moving(void);
|
||||||
int get_honda_brake_prev(void);
|
int get_honda_brake_prev(void);
|
||||||
int get_honda_gas_prev(void);
|
int get_honda_gas_prev(void);
|
||||||
void set_honda_alt_brake_msg(bool);
|
void set_honda_alt_brake_msg(bool);
|
||||||
void set_honda_bosch_hardware(bool);
|
void set_honda_bosch_hardware(bool);
|
||||||
|
int get_honda_bosch_hardware(void);
|
||||||
|
|
||||||
void init_tests_cadillac(void);
|
void init_tests_cadillac(void);
|
||||||
void set_cadillac_desired_torque_last(int t);
|
void set_cadillac_desired_torque_last(int t);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,7 @@ struct sample_t subaru_torque_driver;
|
|||||||
TIM_TypeDef timer;
|
TIM_TypeDef timer;
|
||||||
TIM_TypeDef *TIM2 = &timer;
|
TIM_TypeDef *TIM2 = &timer;
|
||||||
|
|
||||||
|
// from config.h
|
||||||
#define MIN(a,b) \
|
#define MIN(a,b) \
|
||||||
({ __typeof__ (a) _a = (a); \
|
({ __typeof__ (a) _a = (a); \
|
||||||
__typeof__ (b) _b = (b); \
|
__typeof__ (b) _b = (b); \
|
||||||
@@ -42,6 +44,24 @@ TIM_TypeDef *TIM2 = &timer;
|
|||||||
__typeof__ (b) _b = (b); \
|
__typeof__ (b) _b = (b); \
|
||||||
_a > _b ? _a : _b; })
|
_a > _b ? _a : _b; })
|
||||||
|
|
||||||
|
// from llcan.h
|
||||||
|
#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF)
|
||||||
|
#define GET_LEN(msg) ((msg)->RDTR & 0xf)
|
||||||
|
#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21))
|
||||||
|
#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||||
|
#define GET_BYTES_04(msg) ((msg)->RDLR)
|
||||||
|
#define GET_BYTES_48(msg) ((msg)->RDHR)
|
||||||
|
|
||||||
|
// from board_declarations.h
|
||||||
|
#define HW_TYPE_UNKNOWN 0U
|
||||||
|
#define HW_TYPE_WHITE_PANDA 1U
|
||||||
|
#define HW_TYPE_GREY_PANDA 2U
|
||||||
|
#define HW_TYPE_BLACK_PANDA 3U
|
||||||
|
#define HW_TYPE_PEDAL 4U
|
||||||
|
|
||||||
|
// from main_declarations.h
|
||||||
|
uint8_t hw_type = 0U;
|
||||||
|
|
||||||
#define UNUSED(x) (void)(x)
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
#define PANDA
|
#define PANDA
|
||||||
@@ -81,6 +101,10 @@ int get_gas_interceptor_prev(void){
|
|||||||
return gas_interceptor_prev;
|
return gas_interceptor_prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_hw_type(void){
|
||||||
|
return hw_type;
|
||||||
|
}
|
||||||
|
|
||||||
void set_timer(uint32_t t){
|
void set_timer(uint32_t t){
|
||||||
timer.CNT = t;
|
timer.CNT = t;
|
||||||
}
|
}
|
||||||
@@ -199,8 +223,8 @@ void set_subaru_desired_torque_last(int t){
|
|||||||
subaru_desired_torque_last = t;
|
subaru_desired_torque_last = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_honda_ego_speed(void){
|
bool get_honda_moving(void){
|
||||||
return honda_ego_speed;
|
return honda_moving;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_honda_brake_prev(void){
|
int get_honda_brake_prev(void){
|
||||||
@@ -219,7 +243,17 @@ void set_honda_bosch_hardware(bool c){
|
|||||||
honda_bosch_hardware = c;
|
honda_bosch_hardware = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_honda_bosch_hardware(void) {
|
||||||
|
return honda_bosch_hardware;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_tests(void){
|
||||||
|
// get HW_TYPE from env variable set in test.sh
|
||||||
|
hw_type = atoi(getenv("HW_TYPE"));
|
||||||
|
}
|
||||||
|
|
||||||
void init_tests_toyota(void){
|
void init_tests_toyota(void){
|
||||||
|
init_tests();
|
||||||
toyota_torque_meas.min = 0;
|
toyota_torque_meas.min = 0;
|
||||||
toyota_torque_meas.max = 0;
|
toyota_torque_meas.max = 0;
|
||||||
toyota_desired_torque_last = 0;
|
toyota_desired_torque_last = 0;
|
||||||
@@ -229,6 +263,7 @@ void init_tests_toyota(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_cadillac(void){
|
void init_tests_cadillac(void){
|
||||||
|
init_tests();
|
||||||
cadillac_torque_driver.min = 0;
|
cadillac_torque_driver.min = 0;
|
||||||
cadillac_torque_driver.max = 0;
|
cadillac_torque_driver.max = 0;
|
||||||
for (int i = 0; i < 4; i++) cadillac_desired_torque_last[i] = 0;
|
for (int i = 0; i < 4; i++) cadillac_desired_torque_last[i] = 0;
|
||||||
@@ -238,6 +273,7 @@ void init_tests_cadillac(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_gm(void){
|
void init_tests_gm(void){
|
||||||
|
init_tests();
|
||||||
gm_torque_driver.min = 0;
|
gm_torque_driver.min = 0;
|
||||||
gm_torque_driver.max = 0;
|
gm_torque_driver.max = 0;
|
||||||
gm_desired_torque_last = 0;
|
gm_desired_torque_last = 0;
|
||||||
@@ -247,6 +283,7 @@ void init_tests_gm(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_hyundai(void){
|
void init_tests_hyundai(void){
|
||||||
|
init_tests();
|
||||||
hyundai_torque_driver.min = 0;
|
hyundai_torque_driver.min = 0;
|
||||||
hyundai_torque_driver.max = 0;
|
hyundai_torque_driver.max = 0;
|
||||||
hyundai_desired_torque_last = 0;
|
hyundai_desired_torque_last = 0;
|
||||||
@@ -256,6 +293,7 @@ void init_tests_hyundai(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_chrysler(void){
|
void init_tests_chrysler(void){
|
||||||
|
init_tests();
|
||||||
chrysler_torque_meas.min = 0;
|
chrysler_torque_meas.min = 0;
|
||||||
chrysler_torque_meas.max = 0;
|
chrysler_torque_meas.max = 0;
|
||||||
chrysler_desired_torque_last = 0;
|
chrysler_desired_torque_last = 0;
|
||||||
@@ -265,6 +303,7 @@ void init_tests_chrysler(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_subaru(void){
|
void init_tests_subaru(void){
|
||||||
|
init_tests();
|
||||||
subaru_torque_driver.min = 0;
|
subaru_torque_driver.min = 0;
|
||||||
subaru_torque_driver.max = 0;
|
subaru_torque_driver.max = 0;
|
||||||
subaru_desired_torque_last = 0;
|
subaru_desired_torque_last = 0;
|
||||||
@@ -274,7 +313,8 @@ void init_tests_subaru(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_tests_honda(void){
|
void init_tests_honda(void){
|
||||||
honda_ego_speed = 0;
|
init_tests();
|
||||||
|
honda_moving = false;
|
||||||
honda_brake_prev = 0;
|
honda_brake_prev = 0;
|
||||||
honda_gas_prev = 0;
|
honda_gas_prev = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,17 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
python -m unittest discover .
|
|
||||||
|
# Loop over all hardware types:
|
||||||
|
# HW_TYPE_UNKNOWN 0U
|
||||||
|
# HW_TYPE_WHITE_PANDA 1U
|
||||||
|
# HW_TYPE_GREY_PANDA 2U
|
||||||
|
# HW_TYPE_BLACK_PANDA 3U
|
||||||
|
# HW_TYPE_PEDAL 4U
|
||||||
|
|
||||||
|
# Make sure test fails if one HW_TYPE fails
|
||||||
|
set -e
|
||||||
|
|
||||||
|
for hw_type in 0 1 2 3 4
|
||||||
|
do
|
||||||
|
echo "Testing HW_TYPE: $hw_type"
|
||||||
|
HW_TYPE=$hw_type python -m unittest discover .
|
||||||
|
done
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import libpandasafety_py
|
|||||||
|
|
||||||
MAX_BRAKE = 255
|
MAX_BRAKE = 255
|
||||||
|
|
||||||
|
INTERCEPTOR_THRESHOLD = 328
|
||||||
|
|
||||||
class TestHondaSafety(unittest.TestCase):
|
class TestHondaSafety(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
@@ -31,6 +33,10 @@ class TestHondaSafety(unittest.TestCase):
|
|||||||
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
||||||
to_send[0].RIR = msg << 21
|
to_send[0].RIR = msg << 21
|
||||||
to_send[0].RDLR = buttons << 5
|
to_send[0].RDLR = buttons << 5
|
||||||
|
is_panda_black = self.safety.get_hw_type() == 3 # black_panda
|
||||||
|
honda_bosch_hardware = self.safety.get_honda_bosch_hardware()
|
||||||
|
bus = 1 if is_panda_black and honda_bosch_hardware else 0
|
||||||
|
to_send[0].RDTR = bus << 4
|
||||||
|
|
||||||
return to_send
|
return to_send
|
||||||
|
|
||||||
@@ -66,7 +72,9 @@ class TestHondaSafety(unittest.TestCase):
|
|||||||
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
||||||
to_send[0].RIR = addr << 21
|
to_send[0].RIR = addr << 21
|
||||||
to_send[0].RDTR = 6
|
to_send[0].RDTR = 6
|
||||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8)
|
gas2 = gas * 2
|
||||||
|
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \
|
||||||
|
((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8)
|
||||||
|
|
||||||
return to_send
|
return to_send
|
||||||
|
|
||||||
@@ -99,9 +107,9 @@ class TestHondaSafety(unittest.TestCase):
|
|||||||
self.assertFalse(self.safety.get_controls_allowed())
|
self.assertFalse(self.safety.get_controls_allowed())
|
||||||
|
|
||||||
def test_sample_speed(self):
|
def test_sample_speed(self):
|
||||||
self.assertEqual(0, self.safety.get_honda_ego_speed())
|
self.assertEqual(0, self.safety.get_honda_moving())
|
||||||
self.safety.safety_rx_hook(self._speed_msg(100))
|
self.safety.safety_rx_hook(self._speed_msg(100))
|
||||||
self.assertEqual(100, self.safety.get_honda_ego_speed())
|
self.assertEqual(1, self.safety.get_honda_moving())
|
||||||
|
|
||||||
def test_prev_brake(self):
|
def test_prev_brake(self):
|
||||||
self.assertFalse(self.safety.get_honda_brake_prev())
|
self.assertFalse(self.safety.get_honda_brake_prev())
|
||||||
@@ -176,16 +184,15 @@ class TestHondaSafety(unittest.TestCase):
|
|||||||
|
|
||||||
def test_disengage_on_gas_interceptor(self):
|
def test_disengage_on_gas_interceptor(self):
|
||||||
for long_controls_allowed in [0, 1]:
|
for long_controls_allowed in [0, 1]:
|
||||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
for g in range(0, 0x1000):
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||||
self.safety.set_controls_allowed(1)
|
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201))
|
self.safety.set_controls_allowed(True)
|
||||||
if long_controls_allowed:
|
self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201))
|
||||||
self.assertFalse(self.safety.get_controls_allowed())
|
remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD)
|
||||||
else:
|
self.assertEqual(remain_enabled, self.safety.get_controls_allowed())
|
||||||
self.assertTrue(self.safety.get_controls_allowed())
|
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
self.safety.set_gas_interceptor_detected(False)
|
||||||
self.safety.set_gas_interceptor_detected(False)
|
|
||||||
self.safety.set_long_controls_allowed(True)
|
self.safety.set_long_controls_allowed(True)
|
||||||
|
|
||||||
def test_allow_engage_with_gas_interceptor_pressed(self):
|
def test_allow_engage_with_gas_interceptor_pressed(self):
|
||||||
|
|||||||
@@ -23,16 +23,20 @@ class TestHondaSafety(unittest.TestCase):
|
|||||||
def test_fwd_hook(self):
|
def test_fwd_hook(self):
|
||||||
buss = range(0x0, 0x3)
|
buss = range(0x0, 0x3)
|
||||||
msgs = range(0x1, 0x800)
|
msgs = range(0x1, 0x800)
|
||||||
|
is_panda_black = self.safety.get_hw_type() == 3 # black panda
|
||||||
|
bus_rdr_cam = 2 if is_panda_black else 1
|
||||||
|
bus_rdr_car = 0 if is_panda_black else 2
|
||||||
|
bus_pt = 1 if is_panda_black else 0
|
||||||
|
|
||||||
blocked_msgs = [0xE4, 0x33D]
|
blocked_msgs = [0xE4, 0x33D]
|
||||||
for b in buss:
|
for b in buss:
|
||||||
for m in msgs:
|
for m in msgs:
|
||||||
if b == 0:
|
if b == bus_pt:
|
||||||
fwd_bus = -1
|
fwd_bus = -1
|
||||||
elif b == 1:
|
elif b == bus_rdr_cam:
|
||||||
fwd_bus = -1 if m in blocked_msgs else 2
|
fwd_bus = -1 if m in blocked_msgs else bus_rdr_car
|
||||||
elif b == 2:
|
elif b == bus_rdr_car:
|
||||||
fwd_bus = 1
|
fwd_bus = bus_rdr_cam
|
||||||
|
|
||||||
# assume len 8
|
# assume len 8
|
||||||
self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, self._send_msg(b, m, 8)))
|
self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, self._send_msg(b, m, 8)))
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ RT_INTERVAL = 250000
|
|||||||
|
|
||||||
MAX_TORQUE_ERROR = 350
|
MAX_TORQUE_ERROR = 350
|
||||||
|
|
||||||
|
INTERCEPTOR_THRESHOLD = 475
|
||||||
|
|
||||||
def twos_comp(val, bits):
|
def twos_comp(val, bits):
|
||||||
if val >= 0:
|
if val >= 0:
|
||||||
return val
|
return val
|
||||||
@@ -81,7 +83,9 @@ class TestToyotaSafety(unittest.TestCase):
|
|||||||
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
||||||
to_send[0].RIR = addr << 21
|
to_send[0].RIR = addr << 21
|
||||||
to_send[0].RDTR = 6
|
to_send[0].RDTR = 6
|
||||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8)
|
gas2 = gas * 2
|
||||||
|
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \
|
||||||
|
((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8)
|
||||||
|
|
||||||
return to_send
|
return to_send
|
||||||
|
|
||||||
@@ -145,16 +149,15 @@ class TestToyotaSafety(unittest.TestCase):
|
|||||||
|
|
||||||
def test_disengage_on_gas_interceptor(self):
|
def test_disengage_on_gas_interceptor(self):
|
||||||
for long_controls_allowed in [0, 1]:
|
for long_controls_allowed in [0, 1]:
|
||||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
for g in range(0, 0x1000):
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||||
self.safety.set_controls_allowed(True)
|
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201))
|
self.safety.set_controls_allowed(True)
|
||||||
if long_controls_allowed:
|
self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201))
|
||||||
self.assertFalse(self.safety.get_controls_allowed())
|
remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD)
|
||||||
else:
|
self.assertEqual(remain_enabled, self.safety.get_controls_allowed())
|
||||||
self.assertTrue(self.safety.get_controls_allowed())
|
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
self.safety.set_gas_interceptor_detected(False)
|
||||||
self.safety.set_gas_interceptor_detected(False)
|
|
||||||
self.safety.set_long_controls_allowed(True)
|
self.safety.set_long_controls_allowed(True)
|
||||||
|
|
||||||
def test_allow_engage_with_gas_interceptor_pressed(self):
|
def test_allow_engage_with_gas_interceptor_pressed(self):
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ COPY . /openpilot/panda
|
|||||||
WORKDIR /openpilot/panda/tests/safety_replay
|
WORKDIR /openpilot/panda/tests/safety_replay
|
||||||
RUN git clone https://github.com/commaai/openpilot-tools.git tools || true
|
RUN git clone https://github.com/commaai/openpilot-tools.git tools || true
|
||||||
WORKDIR tools
|
WORKDIR tools
|
||||||
RUN git checkout b6461274d684915f39dc45efc5292ea890698da9
|
RUN git checkout feb724a14f0f5223c700c94317efaf46923fd48a
|
||||||
|
|||||||
@@ -8,13 +8,3 @@ cd capnproto-c++-0.6.1
|
|||||||
make -j4
|
make -j4
|
||||||
make install
|
make install
|
||||||
|
|
||||||
cd ..
|
|
||||||
git clone https://github.com/commaai/c-capnproto.git
|
|
||||||
cd c-capnproto
|
|
||||||
git checkout 2e625acacf58a5f5c8828d8453d1f8dacc700a96
|
|
||||||
git submodule update --init --recursive
|
|
||||||
autoreconf -f -i -s
|
|
||||||
CFLAGS="-fPIC" ./configure --prefix=/usr/local
|
|
||||||
make -j4
|
|
||||||
make install
|
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -3,12 +3,12 @@ set -e
|
|||||||
|
|
||||||
docker build -t tmppilot -f Dockerfile.openpilot .
|
docker build -t tmppilot -f Dockerfile.openpilot .
|
||||||
|
|
||||||
docker run --rm \
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/ && ./test_fingerprints.py'
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/ && ./test_fingerprints.py'
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools")'
|
||||||
docker run --rm \
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools"); exit $(($? & 3))'
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda")'
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover common'
|
||||||
docker run --rm \
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/can'
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda"); exit $(($? & 3))'
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/boardd'
|
||||||
docker run --rm \
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/controls'
|
||||||
-v "$(pwd)"/selfdrive/test/tests/plant/out:/tmp/openpilot/selfdrive/test/tests/plant/out \
|
docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && python -m unittest discover selfdrive/loggerd'
|
||||||
tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/tests/plant && OPTEST=1 ./test_longitudinal.py'
|
docker run --rm -v "$(pwd)"/selfdrive/test/tests/plant/out:/tmp/openpilot/selfdrive/test/tests/plant/out tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/tests/plant && OPTEST=1 ./test_longitudinal.py'
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user