[X9D] RTC. Tx Setup cosmetics
This commit is contained in:
-107
@@ -1,107 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Project/adc/adc.c
|
||||
* @author X9D Application Team
|
||||
* @Hardware version V0.2
|
||||
* @date 11-July-2012
|
||||
* @brief This file provides adc Init and drivers.
|
||||
* *
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "stm32f2xx.h"
|
||||
#include "adc.h"
|
||||
#include "hal.h"
|
||||
#include "msg_que.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "item.h"
|
||||
|
||||
|
||||
|
||||
#define ADC1_DR_ADDRESS ((uint32_t)0x4001204C)
|
||||
//#define ADC2_DR_ADDRESS ((uint32_t)0x4001214C)
|
||||
//#define ADC3_DR_ADDRESS ((uint32_t)0x4001224C)
|
||||
|
||||
__IO uint16_t ADC1ConvertedValue[10] = {0};
|
||||
|
||||
|
||||
void adc_clk_init()
|
||||
{
|
||||
/* Enable peripheral clocks *************************************************/
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOADC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void adc_gpio_init()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
//AIN state
|
||||
/* Configure ADC1 Channel5 pin as analog input ******************************/
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
}
|
||||
void adc_init() //one adc
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
|
||||
adc_clk_init();//enable
|
||||
adc_gpio_init();//AIN
|
||||
|
||||
/* ADC1 regular channel configuration ************************************/
|
||||
ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
|
||||
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //
|
||||
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; //
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; //
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfConversion = 1;//
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
/* ADC Common configuration ********************** ***************************/
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//one ADC
|
||||
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_6Cycles;//6* 1/30M
|
||||
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;//
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; //60M/2
|
||||
ADC_CommonInit(&ADC_CommonInitStructure);
|
||||
|
||||
/* ADC1 regular channel configuration */
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_3Cycles);//
|
||||
|
||||
|
||||
/* DMA2 Stream0 channel0 configuration **************************************/
|
||||
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ADC1ConvertedValue;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
|
||||
DMA_InitStructure.DMA_BufferSize = 1;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
|
||||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
|
||||
DMA_Cmd(DMA2_Stream0, ENABLE);
|
||||
|
||||
/* Enable DMA request after last transfer (Single-ADC mode) */
|
||||
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
|
||||
|
||||
/* Enable ADC1 DMA */
|
||||
ADC_DMACmd(ADC1, ENABLE);
|
||||
|
||||
/* Enable ADC1 */
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Project/adc/adc.h
|
||||
* @author X9D Application Team
|
||||
* @Hardware version V0.2
|
||||
* @date 11-July-2012
|
||||
* @brief This file provides adc Init and drivers.
|
||||
* *
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef _ADC_INIT_H_
|
||||
#define _ADC_INIT_H_
|
||||
|
||||
|
||||
void adc_init();
|
||||
#endif
|
||||
+8
-2
@@ -48,8 +48,6 @@
|
||||
#include "aspi.h"
|
||||
#include "i2c_ee.h"
|
||||
#include "audio_driver.h"
|
||||
#include "delays.h"
|
||||
#include "uart.h"
|
||||
|
||||
#define PERI1_FREQUENCY 30000000
|
||||
#define PERI2_FREQUENCY 60000000
|
||||
@@ -130,4 +128,12 @@ extern volatile uint16_t Analog_values[];
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config );
|
||||
|
||||
#define DEBUG_UART_BAUDRATE 115200
|
||||
|
||||
void uartInit(void);
|
||||
void uartSendChar(uint8_t c);
|
||||
|
||||
void delaysInit(void);
|
||||
void delay_01us(uint16_t nb);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny <shadow@privy.de>
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __DELAYS_H
|
||||
#define __DELAYS_H
|
||||
|
||||
void delaysInit(void);
|
||||
void delay_01us(uint16_t nb);
|
||||
|
||||
|
||||
#endif //__DELAYS_H
|
||||
-282
@@ -1,282 +0,0 @@
|
||||
/*-------------------------------------------------------------------------- */
|
||||
/* RTC controls for STM32 */
|
||||
/* Copyright (c) 2009, Martin Thomas 4/2009, 3BSD-license */
|
||||
/* partly based on code from STMircoelectronics, Peter Dannegger, "LaLaDumm" */
|
||||
/*-------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "stm32f10x.h"
|
||||
#include "rtc.h"
|
||||
|
||||
#define FIRSTYEAR 2000 // start year
|
||||
#define FIRSTDAY 6 // 0 = Sunday
|
||||
|
||||
static const uint8_t DaysInMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : isDST
|
||||
* Description : checks if given time is in Daylight Saving time-span.
|
||||
* Input : time-struct, must be fully populated including weekday
|
||||
* Output : none
|
||||
* Return : false: no DST ("winter"), true: in DST ("summer")
|
||||
* DST according to German standard
|
||||
* Based on code from Peter Dannegger found in the microcontroller.net forum.
|
||||
*******************************************************************************/
|
||||
static bool isDST( const RTC_t *t )
|
||||
{
|
||||
uint8_t wday, month; // locals for faster access
|
||||
|
||||
month = t->month;
|
||||
|
||||
if( month < 3 || month > 10 ) { // month 1, 2, 11, 12
|
||||
return false; // -> Winter
|
||||
}
|
||||
|
||||
wday = t->wday;
|
||||
|
||||
if( t->mday - wday >= 25 && (wday || t->hour >= 2) ) { // after last Sunday 2:00
|
||||
if( month == 10 ) { // October -> Winter
|
||||
return false;
|
||||
}
|
||||
} else { // before last Sunday 2:00
|
||||
if( month == 3 ) { // March -> Winter
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : adjustDST
|
||||
* Description : adjusts time to DST if needed
|
||||
* Input : non DST time-struct, must be fully populated including weekday
|
||||
* Output : time-stuct gets modified
|
||||
* Return : false: no DST ("winter"), true: in DST ("summer")
|
||||
* DST according to German standard
|
||||
* Based on code from Peter Dannegger found in the mikrocontroller.net forum.
|
||||
*******************************************************************************/
|
||||
static bool adjustDST( RTC_t *t )
|
||||
{
|
||||
uint8_t hour, day, wday, month; // locals for faster access
|
||||
|
||||
hour = t->hour;
|
||||
day = t->mday;
|
||||
wday = t->wday;
|
||||
month = t->month;
|
||||
|
||||
if ( isDST(t) ) {
|
||||
t->dst = 1;
|
||||
hour++; // add one hour
|
||||
if( hour == 24 ){ // next day
|
||||
hour = 0;
|
||||
wday++; // next weekday
|
||||
if( wday == 7 ) {
|
||||
wday = 0;
|
||||
}
|
||||
if( day == DaysInMonth[month-1] ) { // next month
|
||||
day = 0;
|
||||
month++;
|
||||
}
|
||||
day++;
|
||||
}
|
||||
t->month = month;
|
||||
t->hour = hour;
|
||||
t->mday = day;
|
||||
t->wday = wday;
|
||||
return true;
|
||||
} else {
|
||||
t->dst = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : counter_to_struct
|
||||
* Description : populates time-struct based on counter-value
|
||||
* Input : - counter-value (unit seconds, 0 -> 1.1.2000 00:00:00),
|
||||
* - Pointer to time-struct
|
||||
* Output : time-struct gets populated, DST not taken into account here
|
||||
* Return : none
|
||||
* Based on code from Peter Dannegger found in the mikrocontroller.net forum.
|
||||
*******************************************************************************/
|
||||
static void counter_to_struct( uint32_t sec, RTC_t *t )
|
||||
{
|
||||
uint16_t day;
|
||||
uint8_t year;
|
||||
uint16_t dayofyear;
|
||||
uint8_t leap400;
|
||||
uint8_t month;
|
||||
|
||||
t->sec = sec % 60;
|
||||
sec /= 60;
|
||||
t->min = sec % 60;
|
||||
sec /= 60;
|
||||
t->hour = sec % 24;
|
||||
day = (uint16_t)(sec / 24);
|
||||
|
||||
t->wday = (day + FIRSTDAY) % 7; // weekday
|
||||
|
||||
year = FIRSTYEAR % 100; // 0..99
|
||||
leap400 = 4 - ((FIRSTYEAR - 1) / 100 & 3); // 4, 3, 2, 1
|
||||
|
||||
for(;;) {
|
||||
dayofyear = 365;
|
||||
if( (year & 3) == 0 ) {
|
||||
dayofyear = 366; // leap year
|
||||
if( year == 0 || year == 100 || year == 200 ) { // 100 year exception
|
||||
if( --leap400 ) { // 400 year exception
|
||||
dayofyear = 365;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( day < dayofyear ) {
|
||||
break;
|
||||
}
|
||||
day -= dayofyear;
|
||||
year++; // 00..136 / 99..235
|
||||
}
|
||||
t->year = year + FIRSTYEAR / 100 * 100; // + century
|
||||
|
||||
if( dayofyear & 1 && day > 58 ) { // no leap year and after 28.2.
|
||||
day++; // skip 29.2.
|
||||
}
|
||||
|
||||
for( month = 1; day >= DaysInMonth[month-1]; month++ ) {
|
||||
day -= DaysInMonth[month-1];
|
||||
}
|
||||
|
||||
t->month = month; // 1..12
|
||||
t->mday = day + 1; // 1..31
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : struct_to_counter
|
||||
* Description : calculates second-counter from populated time-struct
|
||||
* Input : Pointer to time-struct
|
||||
* Output : none
|
||||
* Return : counter-value (unit seconds, 0 -> 1.1.2000 00:00:00),
|
||||
* Based on code from "LalaDumm" found in the mikrocontroller.net forum.
|
||||
*******************************************************************************/
|
||||
static uint32_t struct_to_counter( const RTC_t *t )
|
||||
{
|
||||
uint16_t i;
|
||||
uint32_t result = 0;
|
||||
uint16_t idx, year;
|
||||
|
||||
year = t->year;
|
||||
|
||||
/* Calculate days of years before */
|
||||
result = (uint32_t)year * 365;
|
||||
if (t->year >= 1) {
|
||||
result += (year + 3) / 4;
|
||||
result -= (year - 1) / 100;
|
||||
result += (year - 1) / 400;
|
||||
}
|
||||
|
||||
/* Start with 2000 a.d. */
|
||||
result -= 730485UL;
|
||||
|
||||
/* Make month an array index */
|
||||
idx = t->month - 1;
|
||||
|
||||
/* Loop thru each month, adding the days */
|
||||
for (i = 0; i < idx; i++) {
|
||||
result += DaysInMonth[i];
|
||||
}
|
||||
|
||||
/* Leap year? adjust February */
|
||||
if (year%400 == 0 || (year%4 == 0 && year%100 !=0)) {
|
||||
;
|
||||
} else {
|
||||
if (t->month > 1) {
|
||||
result--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add remaining days */
|
||||
result += t->mday;
|
||||
|
||||
/* Convert to seconds, add all the other stuff */
|
||||
result = (result-1) * 86400L + (uint32_t)t->hour * 3600 +
|
||||
(uint32_t)t->min * 60 + t->sec;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : rtc_gettime
|
||||
* Description : populates structure from HW-RTC, takes DST into account
|
||||
* Input : None
|
||||
* Output : time-struct gets modified
|
||||
* Return : always true/not used
|
||||
*******************************************************************************/
|
||||
bool rtc_gettime (RTC_t *rtc)
|
||||
{
|
||||
uint32_t t;
|
||||
|
||||
while ( ( t = RTC_GetCounter() ) != RTC_GetCounter() ) { ; }
|
||||
counter_to_struct( t, rtc ); // get non DST time
|
||||
adjustDST( rtc );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : my_RTC_SetCounter
|
||||
* Description : sets the hardware-counter
|
||||
* Input : new counter-value
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
static void my_RTC_SetCounter(uint32_t cnt)
|
||||
{
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
/* Change the current time */
|
||||
RTC_SetCounter(cnt);
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : rtc_settime
|
||||
* Description : sets HW-RTC with values from time-struct, takes DST into
|
||||
* account, HW-RTC always running in non-DST time
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : not used
|
||||
*******************************************************************************/
|
||||
bool rtc_settime (const RTC_t *rtc)
|
||||
{
|
||||
uint32_t cnt;
|
||||
RTC_t ts;
|
||||
|
||||
cnt = struct_to_counter( rtc ); // non-DST counter-value
|
||||
counter_to_struct( cnt, &ts ); // normalize struct (for weekday)
|
||||
if ( isDST( &ts ) ) {
|
||||
cnt -= 60*60; // Subtract one hour
|
||||
}
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
my_RTC_SetCounter( cnt );
|
||||
PWR_BackupAccessCmd(DISABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : rtc_init
|
||||
* Description : initializes HW RTC,
|
||||
* sets default time-stamp if RTC has not been initialized before
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : not used
|
||||
* see STM RTC example in the StdPeriph-Library package
|
||||
*******************************************************************************/
|
||||
int rtc_init(void) //not use back_vcc
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef RTC_H_
|
||||
#define RTC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
//#include "interger.h"
|
||||
//#include <stdbool.h>
|
||||
#include "stm32f2xx.h"
|
||||
#ifndef false
|
||||
#define false FALSE
|
||||
#endif
|
||||
#ifndef true
|
||||
#define true TRUE
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t year; /* 1..4095 */
|
||||
uint8_t month; /* 1..12 */
|
||||
uint8_t mday; /* 1..31 */
|
||||
uint8_t wday; /* 0..6, Sunday = 0*/
|
||||
uint8_t hour; /* 0..23 */
|
||||
uint8_t min; /* 0..59 */
|
||||
uint8_t sec; /* 0..59 */
|
||||
uint8_t dst; /* 0 Winter, !=0 Summer */
|
||||
} RTC_t;
|
||||
|
||||
int rtc_init(void);
|
||||
bool rtc_gettime (RTC_t*); /* Get time */
|
||||
bool rtc_settime (const RTC_t*); /* Set time */
|
||||
|
||||
#endif
|
||||
+42
-38
@@ -35,49 +35,53 @@
|
||||
|
||||
void rtc_settime(struct gtm * t)
|
||||
{
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_TimeStruct.RTC_Hours = t->tm_hour;
|
||||
RTC_TimeStruct.RTC_Minutes = t->tm_min;
|
||||
RTC_TimeStruct.RTC_Seconds = t->tm_sec;
|
||||
RTC_DateStruct.RTC_Year = t->tm_year - 100;
|
||||
RTC_DateStruct.RTC_Month = t->tm_mon;
|
||||
RTC_DateStruct.RTC_Date = t->tm_mday;
|
||||
|
||||
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_TimeStruct.RTC_Hours = t->tm_hour;
|
||||
RTC_TimeStruct.RTC_Minutes = t->tm_min;
|
||||
RTC_TimeStruct.RTC_Seconds = t->tm_sec;
|
||||
RTC_DateStruct.RTC_Year = t->tm_year - 100;
|
||||
RTC_DateStruct.RTC_Month = t->tm_mon;
|
||||
RTC_DateStruct.RTC_Date = t->tm_mday;
|
||||
|
||||
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
}
|
||||
|
||||
void rtc_gettime(struct gtm * t)
|
||||
{
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
|
||||
t->tm_hour = RTC_TimeStruct.RTC_Hours;
|
||||
t->tm_min = RTC_TimeStruct.RTC_Minutes;
|
||||
t->tm_sec = RTC_TimeStruct.RTC_Seconds;
|
||||
t->tm_year = RTC_DateStruct.RTC_Year + 100;
|
||||
t->tm_mon = RTC_DateStruct.RTC_Month;
|
||||
t->tm_mday = RTC_DateStruct.RTC_Date;
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
|
||||
t->tm_hour = RTC_TimeStruct.RTC_Hours;
|
||||
t->tm_min = RTC_TimeStruct.RTC_Minutes;
|
||||
t->tm_sec = RTC_TimeStruct.RTC_Seconds;
|
||||
t->tm_year = RTC_DateStruct.RTC_Year + 100;
|
||||
t->tm_mon = RTC_DateStruct.RTC_Month;
|
||||
t->tm_mday = RTC_DateStruct.RTC_Date;
|
||||
}
|
||||
|
||||
void rtc_init()
|
||||
void rtcInit()
|
||||
{
|
||||
RTC_InitTypeDef RTC_InitStruct;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
||||
RCC_RTCCLKCmd(ENABLE);
|
||||
|
||||
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
|
||||
RTC_InitStruct.RTC_AsynchPrediv = 128;
|
||||
RTC_InitStruct.RTC_SynchPrediv = 256;
|
||||
|
||||
RTC_Init(&RTC_InitStruct);
|
||||
RTC_InitTypeDef RTC_InitStruct;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
||||
RCC_RTCCLKCmd(ENABLE);
|
||||
|
||||
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
|
||||
RTC_InitStruct.RTC_AsynchPrediv = 128;
|
||||
RTC_InitStruct.RTC_SynchPrediv = 256;
|
||||
|
||||
RTC_Init(&RTC_InitStruct);
|
||||
|
||||
struct gtm utm;
|
||||
rtc_gettime(&utm);
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
|
||||
+16
-16
@@ -35,25 +35,25 @@
|
||||
|
||||
void uartSendChar(uint8_t c)
|
||||
{
|
||||
USART_SendData(UART_DEBUG, c);
|
||||
|
||||
/* Wait for end of previous transfer */
|
||||
while (USART_GetFlagStatus(UART_DEBUG, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(UART_DEBUG, c);
|
||||
|
||||
/* Wait for end of previous transfer */
|
||||
while (USART_GetFlagStatus(UART_DEBUG, USART_FLAG_TC) == RESET);
|
||||
}
|
||||
|
||||
|
||||
void uartInit(void)
|
||||
{
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART_DEBUG, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_RX, GPIO_AF_UART);
|
||||
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_TX, GPIO_AF_UART);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART_TX | GPIO_PIN_UART_RX;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART_DEBUG, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_RX, GPIO_AF_UART);
|
||||
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_TX, GPIO_AF_UART);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART_TX | GPIO_PIN_UART_RX;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
@@ -67,7 +67,7 @@ void uartInit(void)
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
|
||||
USART_Init(UART_DEBUG, &USART_InitStructure);
|
||||
USART_Cmd(UART_DEBUG, ENABLE);
|
||||
USART_Init(UART_DEBUG, &USART_InitStructure);
|
||||
USART_Cmd(UART_DEBUG, ENABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny <shadow@privy.de>
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __UART_H
|
||||
#define __UART_H
|
||||
|
||||
#define DEBUG_UART_BAUDRATE 115200
|
||||
|
||||
void uartInit(void);
|
||||
void uartSendChar(uint8_t c);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user