Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
40d8fac0
Commit
40d8fac0
authored
Aug 26, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtc: Sends tick events. Sleep mode has been temporarily reduced to EM1.
parent
dc4da6b0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
192 additions
and
3 deletions
+192
-3
rtc.c
sw/common/drivers/rtc.c
+102
-0
rtc.h
sw/common/drivers/rtc.h
+61
-0
event.h
sw/common/event.h
+2
-1
Makefile
sw/freertos/Makefile
+1
-0
FreeRTOSConfig.h
sw/freertos/src/FreeRTOSConfig.h
+1
-1
irq_dispatcher.c
sw/freertos/src/irq_dispatcher.c
+23
-1
main.c
sw/freertos/src/main.c
+2
-0
No files found.
sw/common/drivers/rtc.c
0 → 100644
View file @
40d8fac0
/*
* Copyright (C) 2014 Julian Lewis
* @author Matthieu Cattin <matthieu.cattin@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Real time clock routines.
*/
#include "rtc.h"
#include <em_burtc.h>
#include <em_rmu.h>
#include <em_cmu.h>
#define LFXO_FREQUENCY 32768
#define WAKEUP_INTERVAL_MS 1200
#define BURTC_COUNT_BETWEEN_WAKEUP (((LFXO_FREQUENCY * WAKEUP_INTERVAL_MS) / 1000)-1)
struct
rtc_time
time
=
{
0
,
0
};
__attribute__
((
weak
))
void
BURTC_IRQHandler
(
void
)
{
rtc_tick
();
BURTC_IntClear
(
BURTC_IFC_COMP0
);
}
void
rtc_init
(
void
)
{
// Enable LFXO and select it for LFA branch
CMU_OscillatorEnable
(
cmuOsc_LFXO
,
true
,
true
);
CMU_ClockSelectSet
(
cmuClock_LFA
,
cmuSelect_LFXO
);
// Enable low energy clocking module clock
CMU_ClockEnable
(
cmuClock_CORELE
,
true
);
// Enable BURTC registers access
RMU_ResetControl
(
rmuResetBU
,
false
);
BURTC_Init_TypeDef
burtcInit
=
BURTC_INIT_DEFAULT
;
burtcInit
.
enable
=
true
;
// Enable BURTC after initialization
burtcInit
.
mode
=
burtcModeEM3
;
// BURTC is enabled in EM0-EM3
burtcInit
.
debugRun
=
false
;
// Counter shall keep running during debug halt.
burtcInit
.
clkSel
=
burtcClkSelLFXO
;
// Select LFXO as clock source
burtcInit
.
clkDiv
=
burtcClkDiv_1
;
// Clock prescaler
burtcInit
.
lowPowerComp
=
0
;
// Number of least significantt clock bits to ignore in low power mode
burtcInit
.
timeStamp
=
true
;
// Enable time stamp on entering backup power domain
burtcInit
.
compare0Top
=
true
;
// Clear counter on compare match
burtcInit
.
lowPowerMode
=
burtcLPDisable
;
// Low power operation mode, requires LFXO or LFRCO
BURTC_CompareSet
(
0
,
BURTC_COUNT_BETWEEN_WAKEUP
);
// Set top value for comparator
// Enabling Interrupt from BURTC
NVIC_EnableIRQ
(
BURTC_IRQn
);
BURTC_IntEnable
(
BURTC_IF_COMP0
);
// Enable compare interrupt flag
// Initialize BURTC
BURTC_Init
(
&
burtcInit
);
}
struct
rtc_time
rtc_get_time
(
void
)
{
return
time
;
}
void
rtc_set_time
(
struct
rtc_time
current
)
{
time
=
current
;
}
void
rtc_tick
(
void
)
{
++
time
.
epoch
;
time
.
msecs
+=
200
;
if
(
time
.
msecs
==
1000
)
{
++
time
.
epoch
;
time
.
msecs
=
0
;
}
}
sw/common/drivers/rtc.h
0 → 100644
View file @
40d8fac0
/*
* Copyright (C) 2014 Julian Lewis
* @author Matthieu Cattin <matthieu.cattin@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Real time clock routines.
*/
#ifndef RTC_H
#define RTC_H
struct
rtc_time
{
///> Seconds since 01-01-1970 00:00
unsigned
int
epoch
;
///> Milliseconds
unsigned
int
msecs
;
};
/**
* @brief Setup backup RTC
* Using LFRCO clock source and enabling interrupt on COMP0 match
*/
void
rtc_init
(
void
);
/**
* @brief Returns the current time.
*/
struct
rtc_time
rtc_get_time
(
void
);
/**
* @brief Sets the time.
*/
void
rtc_set_time
(
struct
rtc_time
current
);
/**
* @brief Function to be called on every timer tick in the interrupt
* servicer routine.
*/
void
rtc_tick
(
void
);
#endif
/* RTC_H */
sw/common/event.h
View file @
40d8fac0
...
...
@@ -32,7 +32,8 @@
*/
enum
event_type
{
BUTTON_PRESSED
,
SENSOR
SENSOR
,
RTC_TICK
};
/**
...
...
sw/freertos/Makefile
View file @
40d8fac0
...
...
@@ -137,6 +137,7 @@ C_SRC += \
../common/emdrv/sleep/src/sleep.c
\
../common/drivers/lcd.c
\
../common/drivers/buttons.c
\
../common/drivers/rtc.c
\
../common/gfx/font_helv11.c
\
../common/gfx/font_helv17.c
\
../common/gfx/font_helv17b.c
\
...
...
sw/freertos/src/FreeRTOSConfig.h
View file @
40d8fac0
...
...
@@ -89,7 +89,7 @@ extern "C" {
/* Available options when configUSE_TICKLESS_IDLE set to 1
* or configUSE_SLEEP_MODE_IN_IDLE set to 1 :
* 1 - EM1, 2 - EM2, 3 - EM3, timer in EM3 is not very accurate*/
#define configSLEEP_MODE (
3
)
#define configSLEEP_MODE (
1
)
/* Definition used only if configUSE_TICKLESS_IDLE == 0 */
#define configUSE_SLEEP_MODE_IN_IDLE ( 1 )
...
...
sw/freertos/src/irq_dispatcher.c
View file @
40d8fac0
...
...
@@ -28,7 +28,10 @@
#include <apps/application.h>
#include <event.h>
#include <drivers/rtc.h>
#include <em_gpio.h>
#include <em_burtc.h>
static
portBASE_TYPE
gpio_irq_dispatcher
(
uint32_t
flags
)
{
...
...
@@ -49,7 +52,7 @@ static portBASE_TYPE gpio_irq_dispatcher(uint32_t flags)
default:
return
xHigherPriorityTaskWoken
;
}
// Post the
byte
to the back of the queue
// Post the
event
to the back of the queue
xQueueSendToBackFromISR
(
appQueue
,
&
evt
,
&
xHigherPriorityTaskWoken
);
return
xHigherPriorityTaskWoken
;
...
...
@@ -81,3 +84,22 @@ void GPIO_ODD_IRQHandler(void)
portEND_SWITCHING_ISR
(
gpio_irq_dispatcher
(
iflags
));
}
void
BURTC_IRQHandler
(
void
)
{
// We have not woken a task at the start of the ISR
portBASE_TYPE
xHigherPriorityTaskWoken
=
pdFALSE
;
rtc_tick
();
// Fill the event data
struct
event
evt
;
evt
.
type
=
RTC_TICK
;
// Post the byte to the back of the queue
xQueueSendToBackFromISR
(
appQueue
,
&
evt
,
&
xHigherPriorityTaskWoken
);
BURTC_IntClear
(
BURTC_IFC_COMP0
);
portEND_SWITCHING_ISR
(
xHigherPriorityTaskWoken
);
}
sw/freertos/src/main.c
View file @
40d8fac0
...
...
@@ -32,6 +32,7 @@
#include <apps/menu.h>
#include <drivers/buttons.h>
#include <drivers/lcd.h>
#include <drivers/rtc.h>
#include <gfx/ui.h>
int
main
(
void
)
...
...
@@ -44,6 +45,7 @@ int main(void)
CMU_ClockEnable
(
cmuClock_GPIO
,
true
);
buttons_init
();
rtc_init
();
lcd_init
();
ui_init
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment