From 0d8c454727cf394da61fef22cc5523686e7f81ab Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 16 Dec 2014 14:24:14 -0500 Subject: [PATCH] Don't fail silently if DIO or PWM allocation fails Change-Id: I800c429507c3436c2d49561ba279700ad52569fe --- hal/include/HAL/Errors.hpp | 2 ++ hal/lib/Athena/Digital.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hal/include/HAL/Errors.hpp b/hal/include/HAL/Errors.hpp index aecc9fd729..35ed9619af 100644 --- a/hal/include/HAL/Errors.hpp +++ b/hal/include/HAL/Errors.hpp @@ -47,6 +47,8 @@ #define ANALOG_TRIGGER_PULSE_OUTPUT_ERROR_MESSAGE "HAL: Attempted to read AnalogTrigger pulse output." #define PARAMETER_OUT_OF_RANGE -1028 #define PARAMETER_OUT_OF_RANGE_MESSAGE "HAL: A parameter is out of range." +#define RESOURCE_IS_ALLOCATED -1029 +#define RESOURCE_IS_ALLOCATED_MESSAGE "HAL: Resource already allocated" #define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error"; #define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object" diff --git a/hal/lib/Athena/Digital.cpp b/hal/lib/Athena/Digital.cpp index 5c3027d72b..7164699067 100644 --- a/hal/lib/Athena/Digital.cpp +++ b/hal/lib/Athena/Digital.cpp @@ -384,7 +384,11 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t *status) { DigitalPort* port = (DigitalPort*) digital_port_pointer; char buf[64]; snprintf(buf, 64, "DIO %d", port->port.pin); - if (DIOChannels->Allocate(port->port.pin, buf) == ~0ul) return false; + if (DIOChannels->Allocate(port->port.pin, buf) == ~0ul) { + *status = RESOURCE_IS_ALLOCATED; + return false; + } + { Synchronized sync(digitalDIOSemaphore); @@ -420,7 +424,11 @@ bool allocatePWMChannel(void* digital_port_pointer, int32_t *status) { DigitalPort* port = (DigitalPort*) digital_port_pointer; char buf[64]; snprintf(buf, 64, "PWM %d", port->port.pin); - if (PWMChannels->Allocate(port->port.pin, buf) == ~0ul) return false; + if (PWMChannels->Allocate(port->port.pin, buf) == ~0ul) { + *status = RESOURCE_IS_ALLOCATED; + return false; + } + if (port->port.pin > tPWM::kNumHdrRegisters-1) { snprintf(buf, 64, "PWM %d and DIO %d", port->port.pin, remapMXPPWMChannel(port->port.pin) + 10); if (DIOChannels->Allocate(remapMXPPWMChannel(port->port.pin) + 10, buf) == ~0ul) return false;