Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Simulator/include/BoardDef/BoardDefs/Uno.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#define NUM_PINS 32

#define PB2 10
#define SS 10
#define MOSI 11
#define MISO 12
#define SCK 13
#define SCK 13

#define A0 14
#define A1 15
#define A2 16
#define A3 17
#define A4 18
#define A5 19

#define SDA 27
#define SCL 28
2 changes: 1 addition & 1 deletion Simulator/include/MockCAN/MockCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MockCAN {
static inline void write(const CAN_message_t& msg) { vehicle_inbox.push(msg); }
static inline void vehicle_write(const CAN_message_t &msg) { vehicle_outbox.push(msg); }
static inline size_t vehicle_avail() { return vehicle_inbox.size(); }
static void teardown();
static inline void teardown() { vehicle_inbox = std::queue<CAN_message_t>(); vehicle_outbox = std::queue<CAN_message_t>(); }
private:
static std::queue<CAN_message_t> vehicle_inbox;
static std::queue<CAN_message_t> vehicle_outbox;
Expand Down
30 changes: 14 additions & 16 deletions Simulator/include/Time/TimeLib.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#pragma once
#include <ctime>
#include <stdint.h>
#include "HTException.h"

typedef enum { timeNotSet, timeNeedsSync, timeSet } timeStatus_t;
typedef time_t(*getExternalTime)();

class teensy3_clock_class {
public:
inline static time_t get() { return rtcTime; }
inline static void set(time_t t) { if (valid) rtcTime = t; }
inline static void teardown() { valid = rtcTime = 0; }

friend uint16_t year();
friend uint16_t month();
friend uint16_t day();
friend uint16_t hour();
friend uint16_t minute();
friend uint16_t second();
inline static time_t get() { if (!valid) throw HTException("RTC Exception", "RTC not configured"); return std::time(0); }
inline static void set(time_t t) {}
inline static void teardown() { valid = false; }

friend void setSyncProvider(getExternalTime sync);

private:
Expand All @@ -26,12 +21,15 @@ class teensy3_clock_class {

extern teensy3_clock_class Teensy3Clock;

uint16_t year() { return localtime(&Teensy3Clock.rtcTime)->tm_year; }
uint16_t month() { return localtime(&Teensy3Clock.rtcTime)->tm_mon; }
uint16_t day() { return localtime(&Teensy3Clock.rtcTime)->tm_mday; }
uint16_t hour() { return localtime(&Teensy3Clock.rtcTime)->tm_hour; }
uint16_t minute() { return localtime(&Teensy3Clock.rtcTime)->tm_min; }
uint16_t second() { return localtime(&Teensy3Clock.rtcTime)->tm_sec; }
inline uint16_t year() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_year + 1900; }
inline uint16_t month() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_mon; }
inline uint16_t day() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_mday; }
inline uint16_t hour() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_hour; }
inline uint16_t minute() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_min; }
inline uint16_t second() { time_t t = Teensy3Clock.get(); return localtime(&t)->tm_sec; }

#define RTC_TSR (second())
#define RTC_TPR (0)

inline void setSyncProvider(getExternalTime sync) {
Teensy3Clock.valid = (sync == teensy3_clock_class::get);
Expand Down
3 changes: 2 additions & 1 deletion Simulator/src/Time/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_library ( TIME SHARED TimeLib.cpp )
target_include_directories ( TIME PUBLIC ${INC}/Time )
target_include_directories ( TIME PUBLIC ${INC}/Time )
target_link_libraries ( TIME PUBLIC CORE )