Sensorian  1.0
C API Reference Guide Library
MCP79410.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #ifndef __MCP79410_H__
29 #define __MCP79410_H__
30 
39 #include "bcm2835.h"
40 
45 #define MCP79410_ADDRESS 0x6f
46 
47 /************************* RTCC Memory map ****************************/
48 
49 #define EEPROM_WRITE 0xae // DEVICE ADDR for EEPROM (writes)
50 #define EEPROM_READ 0xaf // DEVICE ADDR for EEPROM (reads)
51 #define RTCC_WRITE 0xde // DEVICE ADDR for RTCC MCHP (writes)
52 #define RTCC_READ 0xdf // DEVICE ADDR for RTCC MCHP (reads)
53 
54 #define SRAM_PTR 0x20 // pointer of the SRAM area (RTCC)
55 #define EEPROM_SR 0xff // STATUS REGISTER in the EEPROM
56 
57 #define SEC 0x00 // address of SECONDS register
58 #define MIN 0x01 // address of MINUTES register
59 #define HOUR 0x02 // address of HOURS register
60 #define DAY 0x03 // address of DAY OF WK register
61 #define STAT 0x03 // address of STATUS register
62 #define DATE 0x04 // address of DATE register
63 #define MNTH 0x05 // address of MONTH register
64 #define YEAR 0x06 // address of YEAR register
65 #define CTRL 0x07 // address of CONTROL register
66 #define CAL 0x08 // address of CALIB register
67 #define ULID 0x09 // address of UNLOCK ID register
68 
69 #define ALM0SEC 0x0a // address of ALARM0 SEC register
70 #define ALM0MIN 0x0b // address of ALARM0 MIN register
71 #define ALM0HR 0x0c // address of ALARM0 HOUR register
72 #define ALM0WDAY 0x0d // address of ALARM0 CONTR register
73 #define ALM0DATE 0x0e // address of ALARM0 DATE register
74 #define ALM0MTH 0x0f // address of ALARM0 MONTH register
75 
76 #define ALM1SEC 0x11 // address of ALARM1 SEC register
77 #define ALM1MIN 0x12 // address of ALARM1 MIN register
78 #define ALM1HR 0x13 // address of ALARM1 HOUR register
79 #define ALM1WDAY 0x14 // address of ALARM1 CONTR register
80 #define ALM1DATE 0x15 // address of ALARM1 DATE register
81 #define ALM1MTH 0x16 // address of ALARM1 MONTH register
82 
83 #define PWRDNMIN 0x18 // address of T_SAVER MIN(VDD->BAT)
84 #define PWRDNHOUR 0x19 // address of T_SAVER HR (VDD->BAT)
85 #define PWRDNDATE 0x1a // address of T_SAVER DAT(VDD->BAT)
86 #define PWRDNMTH 0x1b // address of T_SAVER MTH(VDD->BAT)
87 
88 #define PWRUPMIN 0x1c // address of T_SAVER MIN(BAT->VDD)
89 #define PWRUPHOUR 0x1d // address of T_SAVER HR (BAT->VDD)
90 #define PWRUPDATE 0x1e // address of T_SAVER DAT(BAT->VDD)
91 #define PWRUPMTH 0x1f // address of T_SAVER MTH(BAT->VDD)
92 
93 /************************GLOBAL CONSTANTS RTCC - INITIALIZATION****************/
94 
95 #define PM 0x20 // post-meridian bit (HOUR)
96 #define HOUR_FORMAT 0x40 // Hour format
97 #define OUT_PIN 0x80 // = b7 (CTRL)
98 #define SQWEN 0x40 // SQWE = b6 (CTRL)
99 #define ALM_NO 0x00 // no alarm activated (CTRL)
100 #define ALM_0 0x10 // ALARM0 is activated (CTRL)
101 #define ALM_1 0x20 // ALARM1 is activated (CTRL)
102 #define ALM_01 0x30 // both alarms are activated (CTRL)
103 #define MFP_01H 0x00 // MFP = SQVAW(01 HERZ) (CTRL)
104 #define MFP_04K 0x01 // MFP = SQVAW(04 KHZ) (CTRL)
105 #define MFP_08K 0x02 // MFP = SQVAW(08 KHZ) (CTRL)
106 #define MFP_32K 0x03 // MFP = SQVAW(32 KHZ) (CTRL)
107 #define MFP_64H 0x04 // MFP = SQVAW(64 HERZ) (CTRL)
108 #define ALMx_POL 0x80 // polarity of MFP on alarm (ALMxCTL)
109 #define ALMxC_SEC 0x00 // ALARM compare on SEC (ALMxCTL)
110 #define ALMxC_MIN 0x10 // ALARM compare on MIN (ALMxCTL)
111 #define ALMxC_HR 0x20 // ALARM compare on HOUR (ALMxCTL)
112 #define ALMxC_DAY 0x30 // ALARM compare on DAY (ALMxCTL)
113 #define ALMxC_DAT 0x40 // ALARM compare on DATE (ALMxCTL)
114 #define ALMxC_ALL 0x70 // ALARM compare on all param(ALMxCTL)
115 #define ALMx_IF 0x08 // MASK of the ALARM_IF (ALMxCTL)
116 
117 #define OSCRUN 0x20 // state of the oscillator(running or not)
118 #define PWRFAIL 0x10
119 #define VBATEN 0x08 // enable battery for back-up
120 #define VBAT_DIS 0x37 // disable battery back-up
121 
122 #define START_32KHZ 0x80 // start crystal: ST = b7 (SEC)
123 #define LP 0x20 // mask for the leap year bit(MONTH REG)
124 #define HOUR_12 0x40 // 12 hours format (HOUR)
125 
126 #define LPYR 0x20
127 
128 
129 /********************************************************************************/
130 #define ALM1MSK2 0x40
131 #define ALM1MSK1 0x20
132 #define ALM1MSK0 0x10
133 
134 #define ALM0MSK2 0x40
135 #define ALM0MSK1 0x20
136 #define ALM0MSK0 0x10
137 
138 /*********************************************************************************/
139 
143 typedef struct _RTCC_Struct
144 {
145  unsigned char sec;
146  unsigned char min;
147  unsigned char hour;
148  unsigned char weekday;
149  unsigned char date;
150  unsigned char month;
151  unsigned char year;
152 } RTCC_Struct;
153 
157 typedef enum Alarm {ZERO = 0, ONE} Alarm_t;
158 
162 typedef enum AlarmStatus {NOT_SET = 0, SET} AlarmStatus_t;
163 
167 typedef enum PMAM {AMT = 0, PMT} PMAM_t;
168 
172 typedef enum Format {H24 = 0, H12} Format_t;
173 
178 
183 
187 typedef enum MFP_POL {LOWPOL = 0, HIGHPOL} Polarity_t;
188 
189 
190 #define TRUE 1
191 #define FALSE 0
192 
193 /***************************Function definitions********************************************/
194 
195 void MCP79410_Initialize(void);
196 void MCP79410_EnableOscillator(void);
197 void MCP79410_DisableOscillator(void);
198 unsigned char MCP79410_IsRunning(void);
199 
201 void MCP79410_SetTime(RTCC_Struct *time);
202 void MCP79410_SetHourFormat(Format_t format);
203 void MCP79410_SetPMAM(PMAM_t meridian);
204 
205 void MCP79410_EnableAlarm(Alarm_t alarm);
206 void MCP79410_DisableAlarm(Alarm_t alarm);
209 void MCP79410_SetAlarmTime(RTCC_Struct *time, Alarm_t alarm);
211 void MCP79410_SetAlarmMatch(Match_t match,Alarm_t alarm);
214 
215 unsigned char MCP79410_CheckPowerFailure(void);
216 unsigned char MCP79410_IsVbatEnabled(void);
217 void MCP79410_EnableVbat(void);
218 void MCP79410_DisableVbat(void);
221 
222 unsigned char MCP79410_dec2bcd(unsigned char num);
223 unsigned char MCP79410_bcd2dec(unsigned char num);
224 
225 void MCP79410_Write(unsigned char rtcc_reg, unsigned char data);
226 unsigned char MCP79410_Read(unsigned char rtcc_reg);
227 
228 #endif
229 
Definition: MCP79410.h:172
Definition: MCP79410.h:172
Definition: MCP79410.h:167
void MCP79410_SetMFP_GPOStatus(Polarity_t status)
This function sets the MFP output logic level when the pin is configured as GPO.
Definition: MCP79410.c:447
unsigned char MCP79410_dec2bcd(unsigned char num)
Convert Binary Coded Decimal (BCD) to Decimal.
Definition: MCP79410.c:560
unsigned char MCP79410_Read(unsigned char rtcc_reg)
Definition: MCP79410.c:593
void MCP79410_EnableAlarm(Alarm_t alarm)
This function sets the alarm time.
Definition: MCP79410.c:222
void MCP79410_SetAlarmMatch(Match_t match, Alarm_t alarm)
Alarm Asserts on Match on seconds, minutes ,hours depending on match parameter.
Definition: MCP79410.c:364
void MCP79410_DisableVbat(void)
This function disables the backup battery functionality.
Definition: MCP79410.c:515
void MCP79410_DisableOscillator(void)
Disables the clock oscillator.The RTCC does not operate once the oscillator is stopped.
Definition: MCP79410.c:73
enum Format Format_t
AlarmStatus
Definition: MCP79410.h:162
Format
Definition: MCP79410.h:172
unsigned char year
Month.
Definition: MCP79410.h:151
Alarm
Definition: MCP79410.h:157
unsigned char MCP79410_IsRunning(void)
Checks if the chip clock is running.
Definition: MCP79410.c:84
void MCP79410_SetTime(RTCC_Struct *time)
This function initializes the RTCC with a specific time contained in the time structure.
Definition: MCP79410.c:125
void MCP79410_Write(unsigned char rtcc_reg, unsigned char data)
The below function writes a data byte in the I2C RTCC.
Definition: MCP79410.c:583
unsigned char date
Weekday.
Definition: MCP79410.h:149
unsigned char MCP79410_CheckPowerFailure(void)
This function checks if there was a power failure.
Definition: MCP79410.c:465
Definition: MCP79410.h:157
void MCP79410_SetAlarmMFPPolarity(Polarity_t MFP_pol, Alarm_t alarm)
This function sets the MFP polarity either high or low.
Definition: MCP79410.c:331
RTCC_Struct * MCP79410_GetTime(void)
The function returns a time structure with the current time from the RTCC.
Definition: MCP79410.c:100
unsigned char weekday
Hours, (Format used : Standard / Military)
Definition: MCP79410.h:148
unsigned char month
Date of the month.
Definition: MCP79410.h:150
unsigned char sec
Definition: MCP79410.h:145
void MCP79410_EnableOscillator(void)
Enables the clock oscillator. This must be enabled in order for the RTCC to run.
Definition: MCP79410.c:62
void MCP79410_ClearInterruptFlag(Alarm_t alarm)
Clears the interrupt alarm flag.
Definition: MCP79410.c:276
enum MFP_POL Polarity_t
AlarmStatus_t MCP79410_GetAlarmStatus(Alarm_t alarm)
This function gets the status of the alarm interrupt flag.
Definition: MCP79410.c:258
enum Alarm Alarm_t
void MCP79410_Initialize(void)
Initializes the RTCC with the system time.
Definition: MCP79410.c:43
Match
Definition: MCP79410.h:177
void MCP79410_SetHourFormat(Format_t format)
This function sets the hour format.
Definition: MCP79410.c:184
void MCP79410_EnableVbat(void)
This function enables backup battery mode.
Definition: MCP79410.c:503
struct _RTCC_Struct RTCC_Struct
PMAM
Definition: MCP79410.h:167
void MCP79410_SetAlarmTime(RTCC_Struct *time, Alarm_t alarm)
This function sets the alarm time for one of the two alarms.
Definition: MCP79410.c:297
enum Match Match_t
Definition: MCP79410.h:157
Definition: MCP79410.h:162
MFP_POL
Definition: MCP79410.h:187
Definition: MCP79410.h:182
unsigned char min
Seconds.
Definition: MCP79410.h:146
RTCC_Struct * MCP79410_GetPowerDownTime(void)
This function returns the power-down time of the RTCC.
Definition: MCP79410.c:543
unsigned char hour
Minutes.
Definition: MCP79410.h:147
unsigned char MCP79410_IsVbatEnabled(void)
This function checks if battery mode is enabled.
Definition: MCP79410.c:486
enum MFP_MODE MFP_t
enum AlarmStatus AlarmStatus_t
RTCC_Struct * MCP79410_GetPowerUpTime(void)
This function returns the power-up time of the RTCC.
Definition: MCP79410.c:527
enum PMAM PMAM_t
void MCP79410_DisableAlarm(Alarm_t alarm)
This function disables one of the two alarms.
Definition: MCP79410.c:240
void MCP79410_SetMFP_Functionality(MFP_t mode)
This function sets the MFP pin mode.
Definition: MCP79410.c:414
Definition: MCP79410.h:167
void MCP79410_SetPMAM(PMAM_t meridian)
This function sets the meridian mode.
Definition: MCP79410.c:203
MFP_MODE
Definition: MCP79410.h:182
unsigned char MCP79410_bcd2dec(unsigned char num)
Convert Binary Coded Decimal (BCD) to Decimal.
Definition: MCP79410.c:570