Skip to content

Commit

Permalink
Added axTLS changes related to SDK 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Feb 8, 2017
1 parent afce47c commit db21c1a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Sming/third-party/axtls-8266/replacements/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ extern uint64_t system_mktime(uint32_t year, uint32_t mon, uint32_t day, uint32_

static int errno_var = 0;

int* __errno(void) {
#define WEAK_ATTR __attribute__((weak))

int* WEAK_ATTR __errno(void) {
// DEBUGV("__errno is called last error: %d (not current)\n", errno_var);
return &errno_var;
}

unsigned long millis(void)
unsigned long WEAK_ATTR millis(void)
{
return system_get_time() / 1000UL;
}

unsigned long micros(void)
unsigned long WEAK_ATTR micros(void)
{
return system_get_time();
}
Expand Down Expand Up @@ -79,7 +81,7 @@ static void setServer(int id, const char* name_or_ip)
}
}

void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
void WEAK_ATTR configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{
sntp_stop();

Expand All @@ -93,22 +95,22 @@ void configTime(int timezone, int daylightOffset_sec, const char* server1, const
sntp_init();
}

int clock_gettime(clockid_t unused, struct timespec *tp)
int WEAK_ATTR clock_gettime(clockid_t unused, struct timespec *tp)
{
tp->tv_sec = millis() / 1000;
tp->tv_nsec = micros() * 1000;
return 0;
}

// seconds since 1970
time_t mktime(struct tm *t)
time_t WEAK_ATTR mktime(struct tm *t)
{
// system_mktime expects month in range 1..12
#define START_MONTH 1
return DIFF1900TO1970 + system_mktime(t->tm_year, t->tm_mon + START_MONTH, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
}

time_t time(time_t * t)
time_t WEAK_ATTR time(time_t * t)
{
time_t seconds = sntp_get_current_timestamp();
if (t)
Expand All @@ -118,24 +120,24 @@ time_t time(time_t * t)
return seconds;
}

char* asctime(const struct tm *t)
char* WEAK_ATTR asctime(const struct tm *t)
{
return sntp_asctime(t);
}

struct tm* localtime(const time_t *clock)
struct tm* WEAK_ATTR localtime(const time_t *clock)
{
return sntp_localtime(clock);
}

char* ctime(const time_t *t)
char* WEAK_ATTR ctime(const time_t *t)
{
struct tm* p_tm = localtime(t);
char* result = asctime(p_tm);
return result;
}

int gettimeofday(struct timeval *tp, void *tzp)
int WEAK_ATTR gettimeofday(struct timeval *tp, void *tzp)
{
if (tp)
{
Expand Down

0 comments on commit db21c1a

Please sign in to comment.