Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
ecb7f9fe
Commit
ecb7f9fe
authored
Jul 10, 2015
by
Daniel Campora
Browse files
cc3200: Set simplelink time and date when enabling WLAN.
parent
fa47bebf
Changes
7
Hide whitespace changes
Inline
Side-by-side
cc3200/fatfs/src/diskio.c
View file @
ecb7f9fe
...
...
@@ -10,6 +10,7 @@
#include
<stdbool.h>
#include
"py/mpconfig.h"
#include
"py/obj.h"
#include
"diskio.h"
/* FatFs lower layer API */
#include
"sflash_diskio.h"
/* Serial flash disk IO API */
#if MICROPY_HW_HAS_SDCARD
...
...
@@ -20,6 +21,7 @@
#include
"inc/hw_memmap.h"
#include
"rom_map.h"
#include
"prcm.h"
#include
"pybrtc.h"
#include
"timeutils.h"
/* Definitions of physical drive number for each drive */
...
...
@@ -193,12 +195,7 @@ DWORD get_fattime (
)
{
timeutils_struct_time_t
tm
;
uint32_t
seconds
;
uint16_t
mseconds
;
// Get the time from the on-chip RTC and convert it to struct_time
MAP_PRCMRTCGet
(
&
seconds
,
&
mseconds
);
timeutils_seconds_since_2000_to_struct_time
(
seconds
,
&
tm
);
timeutils_seconds_since_2000_to_struct_time
(
pybrtc_get_seconds
(),
&
tm
);
return
((
tm
.
tm_year
-
1980
)
<<
25
)
|
((
tm
.
tm_mon
)
<<
21
)
|
((
tm
.
tm_mday
)
<<
16
)
|
((
tm
.
tm_hour
)
<<
11
)
|
...
...
cc3200/ftp/ftp.c
View file @
ecb7f9fe
...
...
@@ -895,7 +895,6 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
char
*
type
=
(
fno
->
fattrib
&
AM_DIR
)
?
"d"
:
"-"
;
uint32_t
tseconds
;
uint16_t
mseconds
;
uint
mindex
=
(((
fno
->
fdate
>>
5
)
&
0x0f
)
>
0
)
?
(((
fno
->
fdate
>>
5
)
&
0x0f
)
-
1
)
:
0
;
uint
day
=
((
fno
->
fdate
&
0x1f
)
>
0
)
?
(
fno
->
fdate
&
0x1f
)
:
1
;
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) {
(
fno
->
ftime
>>
11
)
&
0x1f
,
(
fno
->
ftime
>>
5
)
&
0x3f
,
2
*
(
fno
->
ftime
&
0x1f
));
MAP_PRCMRTCGet
(
&
tseconds
,
&
m
seconds
);
tseconds
=
pybrtc_get_
seconds
(
);
if
(
FTP_UNIX_SECONDS_180_DAYS
<
tseconds
-
fseconds
)
{
return
snprintf
(
dest
,
destsize
,
"%srw-rw-r-- 1 root root %9u %s %2u %5u %s
\r\n
"
,
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) {
static
int
ftp_print_eplf_drive
(
char
*
dest
,
uint32_t
destsize
,
char
*
name
)
{
timeutils_struct_time_t
tm
;
uint32_t
tseconds
;
uint16_t
mseconds
;
char
*
type
=
"d"
;
timeutils_seconds_since_2000_to_struct_time
((
FTP_UNIX_TIME_20150101
-
FTP_UNIX_TIME_20000101
),
&
tm
);
MAP_PRCMRTCGet
(
&
tseconds
,
&
m
seconds
);
tseconds
=
pybrtc_get_
seconds
(
);
if
(
FTP_UNIX_SECONDS_180_DAYS
<
tseconds
-
(
FTP_UNIX_TIME_20150101
-
FTP_UNIX_TIME_20000101
))
{
return
snprintf
(
dest
,
destsize
,
"%srw-rw-r-- 1 root root %9u %s %2u %5u %s
\r\n
"
,
type
,
0
,
ftp_month
[(
tm
.
tm_mon
-
1
)].
month
,
tm
.
tm_mday
,
tm
.
tm_year
,
name
);
...
...
cc3200/mods/modutime.c
View file @
ecb7f9fe
...
...
@@ -136,12 +136,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
/// \function time()
/// Returns the number of seconds, as an integer, since 1/1/2000.
STATIC
mp_obj_t
time_time
(
void
)
{
uint32_t
seconds
;
uint16_t
mseconds
;
// get the seconds and the milliseconds from the RTC
MAP_PRCMRTCGet
(
&
seconds
,
&
mseconds
);
return
mp_obj_new_int
(
seconds
);
return
mp_obj_new_int
(
pybrtc_get_seconds
());
}
MP_DEFINE_CONST_FUN_OBJ_0
(
time_time_obj
,
time_time
);
...
...
cc3200/mods/modwlan.c
View file @
ecb7f9fe
...
...
@@ -34,11 +34,18 @@
#include
"py/obj.h"
#include
"py/objstr.h"
#include
"py/runtime.h"
#include
"inc/hw_types.h"
#include
"inc/hw_ints.h"
#include
"inc/hw_memmap.h"
#include
"rom_map.h"
#include
"prcm.h"
#include
"timeutils.h"
#include
"netutils.h"
#include
"modnetwork.h"
#include
"modusocket.h"
#include
"modwlan.h"
#include
"pybioctl.h"
#include
"pybrtc.h"
#include
"debug.h"
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
#include
"serverstask.h"
...
...
@@ -519,8 +526,13 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
// set connection policy to Auto + Fast (tries to connect to the last connected AP)
ASSERT_ON_ERROR
(
sl_WlanPolicySet
(
SL_POLICY_CONNECTION
,
SL_CONNECTION_POLICY
(
1
,
1
,
0
,
0
,
0
),
NULL
,
0
));
}
// set current time and date (needed to validate certificates)
wlan_set_current_time
(
pybrtc_get_seconds
());
// start the servers before returning
wlan_servers_start
();
return
MODWLAN_OK
;
}
return
MODWLAN_ERROR_INVALID_PARAMS
;
...
...
@@ -562,6 +574,20 @@ bool wlan_is_connected (void) {
GET_STATUS_BIT
(
wlan_obj
.
status
,
STATUS_BIT_IP_ACQUIRED
))
||
wlan_obj
.
staconnected
);
}
void
wlan_set_current_time
(
uint32_t
seconds_since_2000
)
{
timeutils_struct_time_t
tm
;
timeutils_seconds_since_2000_to_struct_time
(
seconds_since_2000
,
&
tm
);
SlDateTime_t
sl_datetime
=
{
0
};
sl_datetime
.
sl_tm_day
=
tm
.
tm_mday
;
sl_datetime
.
sl_tm_mon
=
tm
.
tm_mon
;
sl_datetime
.
sl_tm_year
=
tm
.
tm_year
;
sl_datetime
.
sl_tm_hour
=
tm
.
tm_hour
;
sl_datetime
.
sl_tm_min
=
tm
.
tm_min
;
sl_datetime
.
sl_tm_sec
=
tm
.
tm_sec
;
sl_DevSet
(
SL_DEVICE_GENERAL_CONFIGURATION
,
SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME
,
sizeof
(
SlDateTime_t
),
(
_u8
*
)(
&
sl_datetime
));
}
//*****************************************************************************
// DEFINE STATIC FUNCTIONS
//*****************************************************************************
...
...
@@ -900,6 +926,8 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *args) {
wlan_servers_start
();
}
}
// set current time and date (needed to validate certificates)
wlan_set_current_time
(
pybrtc_get_seconds
());
return
mp_const_none
;
}
}
...
...
cc3200/mods/modwlan.h
View file @
ecb7f9fe
...
...
@@ -63,6 +63,7 @@ extern void wlan_start (void);
extern
void
wlan_get_mac
(
uint8_t
*
macAddress
);
extern
void
wlan_get_ip
(
uint32_t
*
ip
);
extern
bool
wlan_is_connected
(
void
);
extern
void
wlan_set_current_time
(
uint32_t
seconds_since_2000
);
extern
int
wlan_gethostbyname
(
const
char
*
name
,
mp_uint_t
len
,
uint8_t
*
out_ip
,
uint8_t
family
);
extern
int
wlan_socket_socket
(
mod_network_socket_obj_t
*
s
,
int
*
_errno
);
...
...
cc3200/mods/pybrtc.c
View file @
ecb7f9fe
...
...
@@ -41,6 +41,8 @@
#include
"mpcallback.h"
#include
"timeutils.h"
#include
"simplelink.h"
#include
"modnetwork.h"
#include
"modwlan.h"
/// \moduleref pyb
/// \class RTC - real time clock
...
...
@@ -94,6 +96,14 @@ void pybrtc_init(void) {
}
}
uint32_t
pybrtc_get_seconds
(
void
)
{
uint32_t
seconds
;
uint16_t
mseconds
;
MAP_PRCMRTCGet
(
&
seconds
,
&
mseconds
);
return
seconds
;
}
void
pyb_rtc_callback_disable
(
mp_obj_t
self_in
)
{
// check the wake from param
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) {
mseconds
=
RTC_U16MS_CYCLES
(
mseconds
);
MAP_PRCMRTCSet
(
seconds
,
mseconds
);
// set simplelink's time and date, this is needed to verify certificates
SlDateTime_t
sl_datetime
=
{
0
};
sl_datetime
.
sl_tm_day
=
tm
.
tm_mday
;
sl_datetime
.
sl_tm_mon
=
tm
.
tm_mon
;
sl_datetime
.
sl_tm_year
=
tm
.
tm_year
;
sl_datetime
.
sl_tm_hour
=
tm
.
tm_hour
;
sl_datetime
.
sl_tm_min
=
tm
.
tm_min
;
sl_datetime
.
sl_tm_sec
=
tm
.
tm_sec
;
sl_DevSet
(
SL_DEVICE_GENERAL_CONFIGURATION
,
SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME
,
sizeof
(
SlDateTime_t
),
(
_u8
*
)(
&
sl_datetime
));
// set WLAN time and date, this is needed to verify certificates
wlan_set_current_time
(
seconds
);
return
mp_const_none
;
}
}
...
...
cc3200/mods/pybrtc.h
View file @
ecb7f9fe
...
...
@@ -33,7 +33,8 @@
extern
const
mp_obj_type_t
pyb_rtc_type
;
void
pybrtc_init
(
void
);
void
pyb_rtc_callback_disable
(
mp_obj_t
self_in
);
extern
void
pybrtc_init
(
void
);
extern
void
pyb_rtc_callback_disable
(
mp_obj_t
self_in
);
extern
uint32_t
pybrtc_get_seconds
(
void
);
#endif // PYBRTC_H_
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment