Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWIP Changes for time sync and DMA #5

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions contrib/ports/unix/port/include/netif/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void sio_expect_string(u8_t *str, sio_status_t * siostat);
* @param str pointer to a zero terminated string
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_send_string(u8_t *str, sio_status_t * siostat);
//void sio_send_string(u8_t *str, sio_status_t * siostat);

/**
* Flush outbuffer (send everything in buffer now), useful if some layer below is
Expand All @@ -57,4 +57,3 @@ void sio_flush( sio_status_t * siostat );
void sio_change_baud( sioBaudrates baud, sio_status_t * siostat );

#endif

9 changes: 7 additions & 2 deletions src/api/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,14 @@ tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
{
#if LWIP_TCPIP_CORE_LOCKING
LWIP_UNUSED_ARG(sem);
LOCK_TCPIP_CORE();
/* NOTE: Hacky solution to the tx2i and iOBC contention issue.
Originally tx2i and iobc must wait for other to finish before the
other one begins transmisson.
Removing the lock allows then to run simulaniously
Might result in bad checksum or courrpt packets occastionally*/
//LOCK_TCPIP_CORE();
fn(apimsg);
UNLOCK_TCPIP_CORE();
//UNLOCK_TCPIP_CORE();
return ERR_OK;
#else /* LWIP_TCPIP_CORE_LOCKING */
TCPIP_MSG_VAR_DECLARE(msg);
Expand Down
33 changes: 29 additions & 4 deletions src/apps/sntp/sntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
#include "lwip/ip_addr.h"
#include "lwip/pbuf.h"
#include "lwip/dhcp.h"
#include "time_manager.h"


#include <string.h>
#include <time.h>
Expand Down Expand Up @@ -126,6 +128,10 @@
# endif
#endif /* !SNTP_FRAC_TO_US */



// static void SNTP_SET_SYSTEM_TIME(u32_t sec);

/* Configure behaviour depending on native, microsecond or second precision.
* Treat NTP timestamps as signed two's-complement integers. This way,
* timestamps that have the MSB set simply become negative offsets from
Expand All @@ -137,11 +143,28 @@
# define SNTP_SET_SYSTEM_TIME_NTP(s, f) \
SNTP_SET_SYSTEM_TIME_US((u32_t)((s) + DIFF_SEC_1970_2036), SNTP_FRAC_TO_US(f))
# else
# define SNTP_SET_SYSTEM_TIME_NTP(s, f) \
SNTP_SET_SYSTEM_TIME((u32_t)((s) + DIFF_SEC_1970_2036))
// # define SNTP_SET_SYSTEM_TIME_NTP(s, f) SNTP_SET_SYSTEM_TIME((u32_t)((s) + DIFF_SEC_1970_2036))
# define SNTP_SET_SYSTEM_TIME_NTP(s, f) sntp_set_system_time((u32_t)((s) + DIFF_SEC_1970_2036),f)
# endif
#endif /* !SNTP_SET_SYSTEM_TIME_NTP */

static void sntp_set_system_time(u32_t sec, u32_t frac)
{

//convert ntp frac to microseconds
//useconds is divided by 1000 to get ms
u32_t subsecond = SNTP_FRAC_TO_US(frac) / 1000;
Time_setUnixEpoch(sec);
//set subseconds (milliseconds)
SetSubseconds(subsecond);

//Added to only sync one
sntp_stop();

}



/* Get the system time either natively as NTP timestamp or convert from
* Unix time in seconds and microseconds. Take care to avoid overflow if the
* microsecond value is at the maximum of 999999. Also add 0.5 us fudge to
Expand Down Expand Up @@ -329,7 +352,6 @@ sntp_process(const struct sntp_timestamps *timestamps)
#endif /* SNTP_COMP_ROUNDTRIP */

SNTP_SET_SYSTEM_TIME_NTP(sec, frac);
LWIP_UNUSED_ARG(frac); /* might be unused if only seconds are set */
LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %" U32_F " us\n",
sntp_format_time(sec), SNTP_FRAC_TO_US(frac)));
}
Expand Down Expand Up @@ -682,6 +704,9 @@ sntp_init(void)
#endif
#endif /* SNTP_SERVER_ADDRESS */

//set listen mode. Tx2i must set the mode field to be broadcast
sntp_opmode = SNTP_OPMODE_LISTENONLY;

if (sntp_pcb == NULL) {
sntp_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL);
Expand Down Expand Up @@ -945,4 +970,4 @@ sntp_getservername(u8_t idx)
}
#endif /* SNTP_SERVER_DNS */

#endif /* LWIP_UDP */
#endif /* LWIP_UDP */
9 changes: 8 additions & 1 deletion src/include/lwip/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ u32_t sio_write(sio_fd_t fd, const u8_t *data, u32_t len);
void sio_read_abort(sio_fd_t fd);
#endif

/**
* Write a char to output data stream
* @param str pointer to a zero terminated string
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_send_string(u8_t *str, sio_fd_t * siostat, u16_t len);

#ifdef __cplusplus
}
#endif

#endif /* SIO_H */
#endif /* SIO_H */
Loading