Commit 49b78b51 authored by Martin Vítek's avatar Martin Vítek

Add StatusLED class, switched to internal 32kHz oscillator

parent cb3f2664
......@@ -14,6 +14,7 @@
#include "Time.h"
#include "ENC28J60.h"
#include "EEPROM_25AA02E48.h"
#include "StatusLED.h"
using namespace ENC28J60_namespace;
......@@ -26,6 +27,7 @@ ENC28J60 eth(spi, PORT->Group[0], PIN_PA09, PORT->Group[1], PIN_PA10);
EEPROM_25AA02E48 eeprom(spi, PORT->Group[1], PIN_PA11);
Button button_hour(PORT->Group[0], PIN_PA07, 7);
Button button_min(PORT->Group[0], PIN_PA12, 12);
StatusLED led;
NixieClock nixie;
......@@ -38,6 +40,7 @@ NixieClock::NixieClock(): display(),
setlocale(LC_TIME, "cs_CZ");
setenv("TZ","CET-1CEST-2,M3.5.0/+2,M10.5.0/+1",1);
tzset();
time_date.tm_hour = 9;
......
......@@ -13,6 +13,7 @@
#include "Time.h"
#include "ENC28J60.h"
#include "EEPROM_25AA02E48.h"
#include "StatusLED.h"
using namespace ENC28J60_namespace;
......@@ -61,5 +62,6 @@ extern ENC28J60 eth;
extern EEPROM_25AA02E48 eeprom;
extern Button button_hour;
extern Button button_min;
extern StatusLED led;
extern NixieClock nixie;
......@@ -151,7 +151,6 @@ void NixieStack::packet_handler()
case IPV4:
{
//In tx_frame->payload is packet to send
debug.frame_hex(frame);
if (ipv4.decode(frame->payload, tx_frame->payload))
{
memcpy(tx_frame->dest_address, frame->src_address, 6);
......
#pragma once
#include "sam.h"
#include "GPIO.h"
class StatusLED
{
public:
Output led;
public:
StatusLED(): led(PORT->Group[0], PIN_PA06)
{
}
};
\ No newline at end of file
......@@ -16,25 +16,31 @@ System::System()
void System::init_clock()
{
//Enable external 32kHz crystal, 125 092us start-up
SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_STARTUP(0x06) | SYSCTRL_XOSC32K_XTALEN | SYSCTRL_XOSC32K_EN32K;
SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_STARTUP(0x03) | SYSCTRL_XOSC32K_XTALEN | SYSCTRL_XOSC32K_EN32K;
SYSCTRL->XOSC32K.bit.ENABLE = 1;
while (!SYSCTRL->PCLKSR.bit.XOSC32KRDY) ;;
//Enable internal 32kHz oscillator
SYSCTRL->OSC32K.reg = SYSCTRL_OSC32K_CALIB((*(uint32_t *) FUSES_OSC32KCAL_ADDR >> FUSES_OSC32KCAL_Pos)) | SYSCTRL_OSC32K_STARTUP(5) | SYSCTRL_OSC32K_EN32K | SYSCTRL_OSC32K_ENABLE;
while (!SYSCTRL->PCLKSR.bit.OSC32KRDY) ;;
//Set XOSC32K as GCLK1 source
GCLK->GENDIV.reg = GCLK_GENDIV_DIV(1) | GCLK_GENDIV_ID(1);
GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID(1);
//GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(1);
GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSC32K | GCLK_GENCTRL_ID(1);
while(GCLK->STATUS.bit.SYNCBUSY) ;;
//Enable reference clock for DFLL
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(1) | GCLK_CLKCTRL_ID_DFLL48M;
//Disable on-demand mode (errata)
while (!SYSCTRL->PCLKSR.bit.DFLLRDY) ;;
SYSCTRL->DFLLCTRL.reg = 0;
//Get and set coarse and fine values from NVM
while (!SYSCTRL->PCLKSR.bit.DFLLRDY) ;;
SYSCTRL->DFLLVAL.reg = SYSCTRL_DFLLVAL_COARSE((*(uint32_t *) FUSES_DFLL48M_COARSE_CAL_ADDR >> FUSES_DFLL48M_COARSE_CAL_Pos)) |
......
#pragma once
#include "sam.h"
#include <ctime>
#include "NixieClock.h"
#include "StatusLED.h"
//#define CLOCKS_PER_SEC 1000
extern volatile clock_t clk_count;
......@@ -10,8 +14,11 @@ extern volatile time_t seconds;
class Time
{
private:
Output led;
public:
Time()
Time(): led(PORT->Group[0], PIN_PA06)
{ }
void init()
......@@ -65,6 +72,8 @@ class Time
{
if (TC0->COUNT8.INTFLAG.bit.OVF)
{
led.toggle();
clk_count++;
if ((clk_count%1000) == 0) seconds++;
......
......@@ -35,8 +35,6 @@
using namespace ENC28J60_namespace;
Output led(PORT->Group[0], PIN_PA06);
static const ethernet_frame packet = {
{ 0x00, 0x30, 0x4F, 0x08, 0x35, 0x9C },
{ 0x54, 0x10, 0xEC, 0x20, 0xE5, 0xBD },
......@@ -115,10 +113,10 @@ int main(void)
stack.init();
//Send SNTP request on clock1.zcu.cz
//stack.send_sntp_request(IP({147, 228, 57, 10 }));
stack.send_sntp_request(IP({147, 228, 57, 10 }));
//Send SNTP request on ntp.nic.cz
stack.send_sntp_request(IP({217, 31, 202, 100 }));
//stack.send_sntp_request(IP({217, 31, 202, 100 }));
time_t old = 0;
......@@ -140,13 +138,13 @@ int main(void)
boost.protections_handler();
adc.done = false;
led.toggle();
}
if (time(NULL) >= old)
{
old = time(NULL) + 10;
nixie.display_time();
/*
switch (nixie.state)
{
case NixieClock::DISPLAYING_TIME: nixie.display_date();
......@@ -158,45 +156,11 @@ int main(void)
case NixieClock::DISPLAYING_TEMPERATURE: nixie.display_time();
break;
}
*/
}
/*
if (clock() > old)
{
old = clock() + 10;
if (up)
{
i+=1;
if (i == 100) up = false;
}
else
{
i-=1;
if (i == 0) up = true;
}
nixie.separator.set_brightness(i);
}
*/
if ((clock() % 1000) == 0 )
{
//eth.print_connection_status();
//eth.tx_frame_blocking(packet);
/*
if (eth.rx_frame_blocking(arp_frame))
{
//debug.frame(arp_frame);
arp.decode(arp_frame.payload);
}
*/
/*
uart.send("Voltage 12V:\t");
uart.send_dec(adc.value[adc.VOLTAGE_12V]/1000);uart.send('.');uart.send_dec(adc.value[adc.VOLTAGE_12V]%1000);
......
......@@ -307,6 +307,9 @@
<Compile Include="SNTP_client.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="StatusLED.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="Time.cpp">
<SubType>compile</SubType>
</Compile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment