Cleanup and some changes to make implementation a bit more conforming to the standard.

This commit is contained in:
doragasu 2016-03-13 18:29:30 +01:00
parent f14025b1c7
commit 9651692ca2
3 changed files with 93 additions and 124 deletions

View file

@ -20,7 +20,7 @@
#include <ssid_config.h>
// Add extras/sntp component to makefile for this include to work
/* Add extras/sntp component to makefile for this include to work */
#include <sntp.h>
#define SNTP_SERVERS "0.pool.ntp.org", "1.pool.ntp.org", \
@ -29,71 +29,36 @@
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_RATE_MS)
#define UNUSED_ARG(x) (void)x
// Use GPIO pin 2
const int gpio_frc2 = 2;
// 1 Hz blink frequency
const int freq_frc2 = 1;
void SntpTsk(void *pvParameters)
void sntp_tsk(void *pvParameters)
{
char *servers[] = {SNTP_SERVERS};
UNUSED_ARG(pvParameters);
// Wait until we have joined AP and are assigned an IP
/* Wait until we have joined AP and are assigned an IP */
while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) {
vTaskDelayMs(100);
}
// Start SNTP
/* Start SNTP */
printf("Starting SNTP... ");
sntp_set_update_delay(1*60000);
sntp_initialize(1, 0);
/* SNTP will request an update each 5 minutes */
sntp_set_update_delay(5*60000);
/* Set GMT+1 zone, daylight savings off */
const struct timezone tz = {1*60, 0};
/* SNTP initialization */
sntp_initialize(&tz);
/* Servers must be configured right after initialization */
sntp_set_servers(servers, sizeof(servers) / sizeof(char*));
printf("DONE!\n");
// struct timespec ts;
// clock_getres(CLOCK_REALTIME, &ts);
// printf("Time resolution: %d secs, %d nanosecs\n", t.tv_sec, t.tv_nsec);
//
// clock_gettime(CLOCK_REALTIME, &t);
// printf("Time: %d secs, %d nanosecs\n", t.tv_sec, t.tv_nsec);
/* Print date and time each 5 seconds */
while(1) {
vTaskDelayMs(5000);
time_t ts = sntp_get_rtc_time(NULL);
time_t ts = time(NULL);
printf("TIME: %s", ctime(&ts));
}
}
void frc2_interrupt_handler(void)
{
/* FRC2 needs the match register updated on each timer interrupt */
timer_set_frequency(FRC2, freq_frc2);
gpio_toggle(gpio_frc2);
}
// Configure FRC2 to blink the LED. I'm messing with FRC2 just to test if
// it does affect FreeRTOS.
void Frc2Config(void) {
/* configure GPIO */
gpio_enable(gpio_frc2, GPIO_OUTPUT);
gpio_write(gpio_frc2, 1);
/* stop timer and mask its interrupt as a precaution */
timer_set_interrupts(FRC2, false);
timer_set_run(FRC2, false);
/* set up ISR */
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);
/* configure timer frequency */
timer_set_frequency(FRC2, freq_frc2);
/* unmask interrupt and start timer */
timer_set_interrupts(FRC2, true);
timer_set_run(FRC2, true);
}
void user_init(void)
{
uart_set_baud(0, 115200);
@ -108,9 +73,6 @@ void user_init(void)
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&config);
// Mess with FRC2 to test if it interferes with FreeRTOS
Frc2Config();
xTaskCreate(SntpTsk, (signed char *)"SNTP", 1024, NULL, 1, NULL);
xTaskCreate(sntp_tsk, (signed char *)"SNTP", 1024, NULL, 1, NULL);
}