From 40fc8326aa95914791f9ffa2439bdb3968d15121 Mon Sep 17 00:00:00 2001 From: thomasclark Date: Thu, 24 Jul 2014 10:05:24 -0400 Subject: [PATCH] Only create one tGlobal object This fixes a problem with getFPGATime() blocking for around 1 second each time it's called. Change-Id: I8aafb725889c231ffb2c91e7cb4bbb8110474a9d --- hal/lib/Athena/HAL.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/hal/lib/Athena/HAL.cpp b/hal/lib/Athena/HAL.cpp index d4a630ff4c..975f1b7de8 100644 --- a/hal/lib/Athena/HAL.cpp +++ b/hal/lib/Athena/HAL.cpp @@ -16,6 +16,8 @@ const uint32_t dio_kNumSystems = tDIO::kNumSystems; const uint32_t interrupt_kNumSystems = tInterrupt::kNumSystems; const uint32_t kSystemClockTicksPerMicrosecond = 40; +static tGlobal *global; + void* getPort(uint8_t pin) { Port* port = new Port(); @@ -74,10 +76,7 @@ const char* getHALErrorMessage(int32_t code) */ uint16_t getFPGAVersion(int32_t *status) { - tGlobal *global = tGlobal::create(status); - uint16_t version = global->readVersion(status); - delete global; - return version; + return global->readVersion(status); } /** @@ -90,23 +89,17 @@ uint16_t getFPGAVersion(int32_t *status) */ uint32_t getFPGARevision(int32_t *status) { - tGlobal *global = tGlobal::create(status); - uint32_t revision = global->readRevision(status); - delete global; - return revision; + return global->readRevision(status); } /** * Read the microsecond-resolution timer on the FPGA. - * + * * @return The current time in microseconds according to the FPGA (since FPGA reset). */ uint32_t getFPGATime(int32_t *status) { - tGlobal *global = tGlobal::create(status); - uint32_t time = global->readLocalTime(status); - delete global; - return time; + return global->readLocalTime(status); } /** @@ -115,9 +108,7 @@ uint32_t getFPGATime(int32_t *status) void setFPGALED(uint32_t state, int32_t *status) { // XXX: Not supported? - // tGlobal *global = tGlobal::create(status); // global->writeFPGA_LED(state, status); - // delete global; } /** @@ -127,9 +118,7 @@ void setFPGALED(uint32_t state, int32_t *status) int32_t getFPGALED(int32_t *status) { // XXX: Not supported? - // tGlobal *global = tGlobal::create(status); // bool ledValue = global->readFPGA_LED(status); - // delete global; // return ledValue; return 0; // XXX: Dummy value } @@ -183,9 +172,12 @@ int HALInitialize(int mode) nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass = nLoadOut::kTargetClass_RoboRIO; + global = tGlobal::create(&status); + // Kill any previous robot programs std::fstream fs; - fs.open("/var/lock/frc.pid", std::fstream::in | std::fstream::out); // By making this both in/out, it won't give us an error if it doesnt exist + // By making this both in/out, it won't give us an error if it doesnt exist + fs.open("/var/lock/frc.pid", std::fstream::in | std::fstream::out); if (fs.bad()) return 0;