Skip to content

Commit ecb7f9f

Browse files
author
Daniel Campora
committed
cc3200: Set simplelink time and date when enabling WLAN.
1 parent fa47beb commit ecb7f9f

7 files changed

Lines changed: 50 additions & 27 deletions

File tree

cc3200/fatfs/src/diskio.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdbool.h>
1111

1212
#include "py/mpconfig.h"
13+
#include "py/obj.h"
1314
#include "diskio.h" /* FatFs lower layer API */
1415
#include "sflash_diskio.h" /* Serial flash disk IO API */
1516
#if MICROPY_HW_HAS_SDCARD
@@ -20,6 +21,7 @@
2021
#include "inc/hw_memmap.h"
2122
#include "rom_map.h"
2223
#include "prcm.h"
24+
#include "pybrtc.h"
2325
#include "timeutils.h"
2426

2527
/* Definitions of physical drive number for each drive */
@@ -193,12 +195,7 @@ DWORD get_fattime (
193195
)
194196
{
195197
timeutils_struct_time_t tm;
196-
uint32_t seconds;
197-
uint16_t mseconds;
198-
199-
// Get the time from the on-chip RTC and convert it to struct_time
200-
MAP_PRCMRTCGet(&seconds, &mseconds);
201-
timeutils_seconds_since_2000_to_struct_time(seconds, &tm);
198+
timeutils_seconds_since_2000_to_struct_time(pybrtc_get_seconds(), &tm);
202199

203200
return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
204201
((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |

cc3200/ftp/ftp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,6 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
895895

896896
char *type = (fno->fattrib & AM_DIR) ? "d" : "-";
897897
uint32_t tseconds;
898-
uint16_t mseconds;
899898
uint mindex = (((fno->fdate >> 5) & 0x0f) > 0) ? (((fno->fdate >> 5) & 0x0f) - 1) : 0;
900899
uint day = ((fno->fdate & 0x1f) > 0) ? (fno->fdate & 0x1f) : 1;
901900
uint fseconds = timeutils_seconds_since_2000(1980 + ((fno->fdate >> 9) & 0x7f),
@@ -904,7 +903,7 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
904903
(fno->ftime >> 11) & 0x1f,
905904
(fno->ftime >> 5) & 0x3f,
906905
2 * (fno->ftime & 0x1f));
907-
MAP_PRCMRTCGet(&tseconds, &mseconds);
906+
tseconds = pybrtc_get_seconds();
908907
if (FTP_UNIX_SECONDS_180_DAYS < tseconds - fseconds) {
909908
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n",
910909
type, (_u32)fno->fsize, ftp_month[mindex].month, day,
@@ -928,12 +927,11 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
928927
static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name) {
929928
timeutils_struct_time_t tm;
930929
uint32_t tseconds;
931-
uint16_t mseconds;
932930
char *type = "d";
933931

934932
timeutils_seconds_since_2000_to_struct_time((FTP_UNIX_TIME_20150101 - FTP_UNIX_TIME_20000101), &tm);
935933

936-
MAP_PRCMRTCGet(&tseconds, &mseconds);
934+
tseconds = pybrtc_get_seconds();
937935
if (FTP_UNIX_SECONDS_180_DAYS < tseconds - (FTP_UNIX_TIME_20150101 - FTP_UNIX_TIME_20000101)) {
938936
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n",
939937
type, 0, ftp_month[(tm.tm_mon - 1)].month, tm.tm_mday, tm.tm_year, name);

cc3200/mods/modutime.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
136136
/// \function time()
137137
/// Returns the number of seconds, as an integer, since 1/1/2000.
138138
STATIC mp_obj_t time_time(void) {
139-
uint32_t seconds;
140-
uint16_t mseconds;
141-
142-
// get the seconds and the milliseconds from the RTC
143-
MAP_PRCMRTCGet(&seconds, &mseconds);
144-
return mp_obj_new_int(seconds);
139+
return mp_obj_new_int(pybrtc_get_seconds());
145140
}
146141
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
147142

cc3200/mods/modwlan.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@
3434
#include "py/obj.h"
3535
#include "py/objstr.h"
3636
#include "py/runtime.h"
37+
#include "inc/hw_types.h"
38+
#include "inc/hw_ints.h"
39+
#include "inc/hw_memmap.h"
40+
#include "rom_map.h"
41+
#include "prcm.h"
42+
#include "timeutils.h"
3743
#include "netutils.h"
3844
#include "modnetwork.h"
3945
#include "modusocket.h"
4046
#include "modwlan.h"
4147
#include "pybioctl.h"
48+
#include "pybrtc.h"
4249
#include "debug.h"
4350
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
4451
#include "serverstask.h"
@@ -519,8 +526,13 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
519526
// set connection policy to Auto + Fast (tries to connect to the last connected AP)
520527
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1, 1, 0, 0, 0), NULL, 0));
521528
}
529+
530+
// set current time and date (needed to validate certificates)
531+
wlan_set_current_time (pybrtc_get_seconds());
532+
522533
// start the servers before returning
523534
wlan_servers_start();
535+
524536
return MODWLAN_OK;
525537
}
526538
return MODWLAN_ERROR_INVALID_PARAMS;
@@ -562,6 +574,20 @@ bool wlan_is_connected (void) {
562574
GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED)) || wlan_obj.staconnected);
563575
}
564576

577+
void wlan_set_current_time (uint32_t seconds_since_2000) {
578+
timeutils_struct_time_t tm;
579+
timeutils_seconds_since_2000_to_struct_time(seconds_since_2000, &tm);
580+
581+
SlDateTime_t sl_datetime = {0};
582+
sl_datetime.sl_tm_day = tm.tm_mday;
583+
sl_datetime.sl_tm_mon = tm.tm_mon;
584+
sl_datetime.sl_tm_year = tm.tm_year;
585+
sl_datetime.sl_tm_hour = tm.tm_hour;
586+
sl_datetime.sl_tm_min = tm.tm_min;
587+
sl_datetime.sl_tm_sec = tm.tm_sec;
588+
sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (_u8 *)(&sl_datetime));
589+
}
590+
565591
//*****************************************************************************
566592
// DEFINE STATIC FUNCTIONS
567593
//*****************************************************************************
@@ -900,6 +926,8 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *args) {
900926
wlan_servers_start();
901927
}
902928
}
929+
// set current time and date (needed to validate certificates)
930+
wlan_set_current_time (pybrtc_get_seconds());
903931
return mp_const_none;
904932
}
905933
}

cc3200/mods/modwlan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern void wlan_start (void);
6363
extern void wlan_get_mac (uint8_t *macAddress);
6464
extern void wlan_get_ip (uint32_t *ip);
6565
extern bool wlan_is_connected (void);
66+
extern void wlan_set_current_time (uint32_t seconds_since_2000);
6667

6768
extern int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family);
6869
extern int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno);

cc3200/mods/pybrtc.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "mpcallback.h"
4242
#include "timeutils.h"
4343
#include "simplelink.h"
44+
#include "modnetwork.h"
45+
#include "modwlan.h"
4446

4547
/// \moduleref pyb
4648
/// \class RTC - real time clock
@@ -94,6 +96,14 @@ void pybrtc_init(void) {
9496
}
9597
}
9698

99+
uint32_t pybrtc_get_seconds (void) {
100+
uint32_t seconds;
101+
uint16_t mseconds;
102+
103+
MAP_PRCMRTCGet(&seconds, &mseconds);
104+
return seconds;
105+
}
106+
97107
void pyb_rtc_callback_disable (mp_obj_t self_in) {
98108
// check the wake from param
99109
if (pybrtc_data.prwmode & PYB_PWR_MODE_ACTIVE) {
@@ -188,15 +198,8 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
188198
mseconds = RTC_U16MS_CYCLES(mseconds);
189199
MAP_PRCMRTCSet(seconds, mseconds);
190200

191-
// set simplelink's time and date, this is needed to verify certificates
192-
SlDateTime_t sl_datetime = {0};
193-
sl_datetime.sl_tm_day = tm.tm_mday;
194-
sl_datetime.sl_tm_mon = tm.tm_mon;
195-
sl_datetime.sl_tm_year = tm.tm_year;
196-
sl_datetime.sl_tm_hour = tm.tm_hour;
197-
sl_datetime.sl_tm_min = tm.tm_min;
198-
sl_datetime.sl_tm_sec = tm.tm_sec;
199-
sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (_u8 *)(&sl_datetime));
201+
// set WLAN time and date, this is needed to verify certificates
202+
wlan_set_current_time(seconds);
200203
return mp_const_none;
201204
}
202205
}

cc3200/mods/pybrtc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
extern const mp_obj_type_t pyb_rtc_type;
3535

36-
void pybrtc_init(void);
37-
void pyb_rtc_callback_disable (mp_obj_t self_in);
36+
extern void pybrtc_init(void);
37+
extern void pyb_rtc_callback_disable (mp_obj_t self_in);
38+
extern uint32_t pybrtc_get_seconds (void);
3839

3940
#endif // PYBRTC_H_

0 commit comments

Comments
 (0)