Flipklok
 
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
5
6#include <msp430.h>
7#include "pins.h"
8#include "gpio.h"
9#include "clock.h"
10#include "timer.h"
11#include "adc.h"
12#include "stepperAdvance.h"
13#include "fwdButton.h"
14#include "dcfReceive.h"
15#include "led.h"
16#include "timeKeeping.h"
17#include "pinInterrupts.h"
18#include "uart.h"
19
21
22#warning "project > properties > buid > MSP430 compiler > optimization > optimization level"
23#warning "(set to 1 for default, 0 for acces to non global variables while in debug mode)"
24
25// Check if the INFOD section (0x1000 - 0x0040) is NOT within the main FLASH region
26#if ((0x1000 >= __INFOA__) || (0x0040 < __FLASH_START__))
27 #warning ("INFOD (0x1000 - 0x0040) is safe for user data storage.")
28#else
29 #error "Warning: INFOD (0x1000 - 0x0040) is part of FLASH! Do NOT use for data storage."
30#endif
31
32uint32_t setTime;
33uint32_t loaded_value;
34
54void main(void)
55{
56 WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
57 FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
58 #ifdef UART_ENABLED
59 #warning("Warning: UART is enabled! disable define of UART_ENABLED to disable it.")
60 UART_Init(); // Initialize UART
61 #endif
62
63 setupGpio();
64 setupAdc();
67
68 //For testing, setting time of mechanical clock
69 uint32_t setMinute = 44;
70 uint32_t setHour = 17;
71 setTime = setHour * 3600 + setMinute * 60;
72 write_SegD(setTime); // Write 32-bit value to segment C, increment value
73
74 __delay_cycles(100000);
75 loaded_value = load_from_flash(); // Load the value from flash
76 if (loaded_value == 0xFFFFFFFF)
77 {
78 __delay_cycles(100000);
79 __no_operation();
80 while(1)
81 {
82 __no_operation();
83 }
84 }
85 __delay_cycles(100000); //wait time otherwise to quick between writing and reading from flash
87 timeOfLastDcfMessage = mechanicalTimeFloat; // Set the time of DCF before any message received the same as mechanical time so the clock does not stand still at startup
88 #ifdef UART_ENABLED
89 UART_SendString("\r\n------Starting------\r\n");
90 UART_SendString("mechanicalTime: ");
92 #endif
93
96
97 __bis_SR_register(LPM3_bits | GIE);
98}
void setupAdc()
Setup ADC, get called in startup from main(), Shortest samling rate, with 2.5V reference,...
Definition adc.c:86
void setupClocks()
Setup clocks of system, all to LFXTAL input, get called from main()
Definition clock.c:16
void setupGpio()
Setup of all GPIO's on startup, gets called from main()
Definition gpio.c:19
void main(void)
Main function that initializes system components and enters low-power mode.
Definition main.c:54
uint32_t setTime
Definition main.c:32
uint32_t loaded_value
Definition main.c:33
void setupTimer0()
Definition timer.c:26
uint32_t load_from_flash(void)
Function to load a 32-bit value from Flash memory segment D used for restoring the mechanical time on...
void write_SegD(uint32_t value)
Function to write a 32-bit value to Flash segment D for storing the mechanical time,...
uint32_t timeOfLastDcfMessage
Definition timeKeeping.h:21
double mechanicalTimeFloat
Definition timeKeeping.h:40
void resetTimeKeeping()
Reset the time settings on startup, gets called from main()
void setupTimer1()
Definition timer.c:114
void UART_SendTime(uint32_t seconds)
Sends a time formated in hours and minutes to host system.
Definition uart.c:131
void UART_Init(void)
Setup UART communication, gets called from main()
Definition uart.c:18
void UART_SendString(char *str)
send a full string to host system
Definition uart.c:49