Remove obsolete timer functions and replace with std::chrono (#64)

Removed delayTicks(), delayMillis(), delaySeconds(), HAL_NO_WAIT, HAL_WAIT_FOREVER,
niTimestamp32(), and niTimestamp64().

Replaced clock_gettime() and usleep() with std::chrono.
This commit is contained in:
Tyler Veness
2016-05-26 20:19:23 -07:00
committed by Peter Johnson
parent 4af0bbddee
commit fa8bb3fa91
14 changed files with 37 additions and 119 deletions

View File

@@ -32,7 +32,6 @@
#include "SerialPort.h"
#include "Solenoid.h"
#include "Task.h"
#include "Utilities.h"
#define HAL_IO_CONFIG_DATA_SIZE 32
#define HAL_SYS_STATUS_DATA_SIZE 44

View File

@@ -1,19 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
extern "C" {
extern const int32_t HAL_NO_WAIT;
extern const int32_t HAL_WAIT_FOREVER;
void delayTicks(int32_t ticks);
void delayMillis(double ms);
void delaySeconds(double s);
}

View File

@@ -11,6 +11,7 @@
#include <stdio.h>
#include <mutex>
#include <thread>
#include "ChipObject.h"
#include "FRC_NetworkCommunication/LoadOut.h"
@@ -61,7 +62,7 @@ void initializeDigital(int32_t* status) {
// Make sure that the 9403 IONode has had a chance to initialize before
// continuing.
while (pwmSystem->readLoopTiming(status) == 0) delayTicks(1);
while (pwmSystem->readLoopTiming(status) == 0) std::this_thread::yield();
if (pwmSystem->readLoopTiming(status) != kExpectedLoopTiming) {
// TODO: char err[128];

View File

@@ -6,6 +6,7 @@
/*----------------------------------------------------------------------------*/
#include "HAL/HAL.h"
#include "HAL/cpp/priority_mutex.h"
#include <signal.h> // linux for kill
#include <stdlib.h>
@@ -15,6 +16,7 @@
#include <fstream>
#include <iostream>
#include <mutex>
#include <thread>
#include "ChipObject.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
@@ -343,7 +345,7 @@ int HALInitialize(int mode) {
if (pid >= 2 && kill(pid, 0) == 0 && pid != getpid()) {
std::cout << "Killing previously running FRC program..." << std::endl;
kill(pid, SIGTERM); // try to kill it
delayMillis(100);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (kill(pid, 0) == 0) {
// still not successfull
if (mode == 0) {
@@ -388,6 +390,5 @@ void Occur() {}
void imaqGetErrorText() {}
void imaqGetLastError() {}
void niTimestamp64() {}
} // extern "C"

View File

@@ -1,53 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HAL/Utilities.h"
#include <time.h>
const int32_t HAL_NO_WAIT = 0;
const int32_t HAL_WAIT_FOREVER = -1;
extern "C" {
void delayTicks(int32_t ticks) {
struct timespec test, remaining;
test.tv_sec = 0;
test.tv_nsec = ticks * 3;
/* Sleep until the requested number of ticks has passed, with additional
time added if nanosleep is interrupted. */
while (nanosleep(&test, &remaining) == -1) {
test = remaining;
}
}
void delayMillis(double ms) {
struct timespec test, remaining;
test.tv_sec = ms / 1000;
test.tv_nsec = 1000 * (((uint64_t)ms) % 1000000);
/* Sleep until the requested number of milliseconds has passed, with
additional time added if nanosleep is interrupted. */
while (nanosleep(&test, &remaining) == -1) {
test = remaining;
}
}
void delaySeconds(double s) {
struct timespec test, remaining;
test.tv_sec = (int)s;
test.tv_nsec = (s - (int)s) * 1000000000.0;
/* Sleep until the requested number of seconds has passed, with additional
time added if nanosleep is interrupted. */
while (nanosleep(&test, &remaining) == -1) {
test = remaining;
}
}
} // extern "C"

View File

@@ -107,7 +107,6 @@
#include "HAL/CanTalonSRX.h"
#include "FRC_NetworkCommunication/CANSessionMux.h" //CAN Comm
#include <string.h> // memset
#include <unistd.h> // usleep
#define STATUS_1 0x02041400
#define STATUS_2 0x02041440

View File

@@ -3,7 +3,6 @@
#include "ctre/CtreCanNode.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include <string.h> // memset
#include <unistd.h> // usleep
static const UINT32 kFullMessageIDMask = 0x1fffffff;

View File

@@ -3,7 +3,6 @@
#include "ctre/PCM.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include <string.h> // memset
#include <unistd.h> // usleep
/* This can be a constant, as long as nobody needs to update solenoids within
1/50 of a second. */
static const INT32 kCANPeriod = 20;

View File

@@ -1,7 +1,6 @@
#include "ctre/PDP.h"
#include "FRC_NetworkCommunication/CANSessionMux.h" //CAN Comm
#include <string.h> // memset
#include <unistd.h> // usleep
#define STATUS_1 0x8041400
#define STATUS_2 0x8041440