Flipklok
 
Loading...
Searching...
No Matches
main.c File Reference

Startup of system. More...

#include <msp430.h>
#include "pins.h"
#include "gpio.h"
#include "clock.h"
#include "timer.h"
#include "adc.h"
#include "stepperAdvance.h"
#include "fwdButton.h"
#include "dcfReceive.h"
#include "led.h"
#include "timeKeeping.h"
#include "pinInterrupts.h"
#include "uart.h"
#include "storeLoadMechanicalTime.h"

Go to the source code of this file.

Functions

void main (void)
 Main function that initializes system components and enters low-power mode.
 

Variables

uint32_t setTime
 
uint32_t loaded_value
 

Detailed Description

Startup of system.

Definition in file main.c.

Function Documentation

◆ main()

void main ( void )

Main function that initializes system components and enters low-power mode.

This function is responsible for setting up various system components, including the GPIO, ADC, clocks, and timekeeping system. It also loads the mechanical time from flash memory (if it is connected to a debugger the flash is cleared and the mechanical time must be set manually). It also initializes the UART (if enabled). Additionally, the function sets the time of the mechanical clock and enters low-power mode with interrupts enabled. The system performs various initialization tasks to ensure the proper operation of the application.

It performs the following steps:

  • Stops the watchdog timer to prevent system reset.
  • Initializes UART if UART_ENABLED is defined.
  • Sets up GPIO, ADC, clocks, and timekeeping.
  • Writes the stored mechanical time from flash to UART.
  • If the value is invalid because the debugger overwritten the flash, enters an infinite loop.
  • Configures timers and enters low-power mode with interrupts.
Note
If UART is enabled, a warning will be displayed that the UART will be initialized.

Definition at line 54 of file main.c.

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
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

References load_from_flash(), loaded_value, mechanicalTimeFloat, resetTimeKeeping(), setTime, setupAdc(), setupClocks(), setupGpio(), setupTimer0(), setupTimer1(), timeOfLastDcfMessage, UART_Init(), UART_SendString(), UART_SendTime(), and write_SegD().

Variable Documentation

◆ loaded_value

uint32_t loaded_value

Definition at line 33 of file main.c.

Referenced by load_from_flash(), and main().

◆ setTime

uint32_t setTime

Definition at line 32 of file main.c.

Referenced by main().