Ver Fonte

first commit"

CLUZE Remy -EXT há 6 anos atrás
commit
92eb34f321
8 ficheiros alterados com 476 adições e 0 exclusões
  1. 43 0
      Include/Eeprom.h
  2. 29 0
      Include/Heure.h
  3. 42 0
      Include/PWM.h
  4. 91 0
      Include/RTC.h
  5. 31 0
      Source/Eeprom.c
  6. 54 0
      Source/Heure.c
  7. 113 0
      Source/PWM.c
  8. 73 0
      Source/RTC.c

+ 43 - 0
Include/Eeprom.h

@@ -0,0 +1,43 @@
+/*
+ * Eeprom.h
+ *
+ *  Created on: 14 janv. 2019
+ *      Author: e_rcluze
+ *
+ *Le fonctionement de l'Eeprom est en Fifo.
+ *L'adrresse du pointeur de lecture est stocker dans les 16 premier byte de l'eeprom
+ *L'adrresse du pointeur d'ecriture est stocker dans les 16 bit suivant
+ *
+ *
+ *
+ * Penser a ajouter les fonction de lecture ecriture dans le fichier i2c.c "générer"
+ *
+void readEeprom(int add, uint8_t *tab, int len){
+
+}
+
+void writeEeprom(int add, uint8_t *tab, int len){
+
+}
+ *
+ */
+
+#ifndef EEPROM_H_
+#define EEPROM_H_
+
+#define EepromADD 0XA0
+
+uint16_t readPointerEcriture();
+void readPointerEcriture();
+
+uint16_t readPointerLecture();
+void readPointerLecture();
+
+void writeData(uint8_t *tab, uint8_t size);
+
+void readData(uint8_t *tab, uint8_t size);
+
+//fonction pour tester le hard de l'Eeprom
+void testEeprom();
+
+#endif /* EEPROM_H_ */

+ 29 - 0
Include/Heure.h

@@ -0,0 +1,29 @@
+/*
+ * Heure.h
+ *
+ *  Created on: 14 mai 2019
+ *      Author: e_rcluze
+ */
+
+#ifndef HEURE_H_
+#define HEURE_H_
+
+#include "RTC.h"
+
+/**
+ * fonction qui renvoie
+ * 	-1 si h1 est inf�rieur que H2
+ * 	0 si h1 et h2 egale
+ * 	1 si h1 est sup�rieur a h2
+ */
+int8_t CompareHeure(Heure h1,Heure h2);
+
+void HeureAjout(Heure res,Heure h1,uint8_t Pente);
+
+void HeureSuppr(Heure res,Heure h1,uint8_t Pente);
+
+int16_t DiffHeure(Heure h1, Heure h2);
+
+int32_t DiffDate(Date h1, Date h2);
+
+#endif /* HEURE_H_ */

+ 42 - 0
Include/PWM.h

@@ -0,0 +1,42 @@
+/*
+ * PWM.h
+ *
+ *  Created on: 14 janv. 2019
+ *      Author: e_rcluze
+ */
+
+#ifndef PWM_H_
+#define PWM_H_
+
+#include "RTC.h"
+#include "tim.h"
+#include "Heure.h"
+#include "Tab.h"
+
+#define S0 0X00
+#define S1 0X01
+#define S2 0X02
+#define S3 0X03
+#define S4 0X04
+#define S5 0X05
+#define S6 0X06
+#define S7 0X07
+#define S8 0X08
+#define S9 0X09
+
+
+#define PWM_MAX 31250-1
+
+void PWMSetDutyCycle(uint8_t sortie, uint8_t pourcentage);
+
+void PWMStart(uint8_t sortie);
+
+uint16_t PourcentageToValue(uint8_t val);
+
+uint16_t PWMValue();
+
+uint8_t PWMPourcentage(Heure *heure, Sortie *sortie);
+
+uint8_t PWMPourcentageReprise(Heure *Hrepr, Heure *heure, Sortie *sortie);
+
+#endif /* PWM_H_ */

+ 91 - 0
Include/RTC.h

@@ -0,0 +1,91 @@
+/*
+ * RTC.h
+ *
+ *  Created on: 14 janv. 2019
+ *      Author: e_rcluze
+ *
+ * Penser a ajouter les fonction de lecture ecriture dans le fichier i2c.c "générer"
+ *
+ *
+ *
+void readRTC(uint8_t add, uint8_t *tab, int len){
+	uint8_t ad[1];
+	ad[0]=add;
+	HAL_StatusTypeDef res;
+	res = HAL_I2C_Master_Transmit(&hi2c?,RTC_ADD,ad,1,1000);
+	res = HAL_I2C_Master_Receive(&hi2c?,RTC_ADD,tab,len,1000);
+}
+
+void writeRTC(uint8_t add, uint8_t *tab, int len){
+	uint8_t ad[len+1];
+	ad[0]=add;
+	for (int i = 0; i< len;i++){
+		ad[i+1]=tab[i];
+	}
+	HAL_StatusTypeDef res;
+	res = HAL_I2C_Master_Transmit(&hi2c3,RTC_ADD,ad,len+1,1000);
+}
+ *
+ */
+
+#ifndef RTC_H
+#define RTC_H
+
+#include <stdint.h>
+
+#define RTC_ADD 0XD0
+
+#define CENTIEM 			0X00
+#define SECOND				0X01
+#define MINUTES				0X02
+#define HOURS				0X03
+#define DAYWEEK				0X04
+#define DAY					0X05
+#define MONTHS				0X06
+#define YEAR				0X07
+#define CALIBRATION			0X08
+#define WATCHDOG			0X09
+#define ALARM_MONTH			0X0A
+#define ALARM_DAY			0X0B
+#define ALARM_HOURS			0X0C
+#define ALARM_MINUTES		0X0D
+#define ALARM_SECOND		0X0E
+#define FLAGS				0X0F
+#define TIMER_VALUE			0X10
+#define TIMER_CONTROL		0X11
+#define ANALOG_CALIBRATION	0X12
+#define SQW					0X13
+
+typedef struct {
+
+	uint8_t second;
+	uint8_t minute;
+	uint8_t heure;
+	uint8_t jour;
+	uint8_t joursemaine;
+	uint8_t mois;
+	uint8_t annee;
+
+}Date;
+
+typedef struct {
+	uint8_t minute;
+	uint8_t heure;
+}Heure;
+
+void readHeure(Heure *heure);
+
+void readDate(Date *date);
+
+void redemareRTC();
+
+void writeDate(Date *date);
+
+/**
+ * Fonction qui permet de tester le matériel
+ */
+void testRTC();
+
+void testBatteryRTC();
+
+#endif /* RTC_H */

+ 31 - 0
Source/Eeprom.c

@@ -0,0 +1,31 @@
+#include "Eeprom.h"
+
+
+uint16_t readPointerEcriture(){
+
+}
+
+void readPointerEcriture(){
+
+}
+
+uint16_t readPointerLecture(){
+
+}
+
+void readPointerLecture(){
+
+}
+
+void writeData(uint8_t *tab, uint8_t size){
+
+}
+
+void readData(uint8_t *tab, uint8_t size){
+
+}
+
+//fonction pour tester le hard de l'Eeprom
+void testEeprom(){
+
+}

+ 54 - 0
Source/Heure.c

@@ -0,0 +1,54 @@
+/*
+ * Heure.c
+ *
+ *  Created on: 14 mai 2019
+ *      Author: e_rcluze
+ */
+
+#include "RTC.h"
+
+int8_t CompareHeure(Heure h1,Heure h2){
+
+	if( h1.heure==h2.heure){
+		if (h1.minute==h2.minute)
+			return 0;
+		else if (h1.minute<h2.minute)
+			return -1;
+		else
+			return 1;
+	}
+	else if (h1.heure<h2.heure)
+		return -1;
+	else
+		return 1;
+}
+
+void HeureAjout(Heure res,Heure h1,uint8_t Pente){
+	uint8_t minute=h1.minute+Pente;
+	res.heure=h1.heure+minute/60;
+	res.minute=minute%60;
+}
+
+void HeureSuppr(Heure res,Heure h1,uint8_t Pente){
+	int8_t minute=h1.minute-Pente;
+	if (minute<0) {
+		res.heure=h1.heure-1;
+		res.minute=minute+60;
+	}
+	else {
+		res.heure=h1.heure;
+		res.minute=minute;
+	}
+}
+
+int16_t DiffHeure(Heure h1, Heure h2){
+	return ((h1.heure-h2.heure)*60)+(h1.minute-h2.minute);
+}
+
+int32_t DiffDate(Date h1, Date h2){
+	int32_t min = h1.minute - h2.minute;
+	int32_t heure = (h1.heure - h2.heure)*60;
+	int32_t jour = (h1.jour - h2.jour)*24*60;
+	int32_t annee = (h1.annee - h2.annee)*24*60*365;
+	return min+heure+jour+annee;
+}

+ 113 - 0
Source/PWM.c

@@ -0,0 +1,113 @@
+/*
+ * PWM.c
+ *
+ *  Created on: 14 janv. 2019
+ *      Author: e_rcluze
+ */
+
+#include "PWM.h"
+#include "tim.h"
+#include "gpio.h"
+
+void PWMSetDutyCycle(uint8_t sortie, uint8_t pourcentage) {
+	TIM_OC_InitTypeDef sConfigOC;
+
+	sConfigOC.OCMode = TIM_OCMODE_PWM1;
+	sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
+	sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
+
+	sConfigOC.Pulse = PourcentageToValue(pourcentage);
+	HAL_Delay(1);
+	switch (sortie) {
+	case S0:
+		HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3);
+		break;
+	case S1:
+		HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
+		break;
+	case S2:
+		HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);
+		break;
+	case S3:
+		HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2);
+		break;
+	case S4:
+		HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3);
+		break;
+	case S5:
+		HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4);
+		break;
+	case S6:
+		HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1);
+		break;
+	case S7:
+		HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2);
+		break;
+	case S8:
+		HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3);
+		break;
+	case S9:
+		HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4);
+		break;
+	}
+}
+
+void PWMStart(uint8_t sortie) {
+	switch (sortie) {
+	case S0:
+		HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
+		break;
+	case S1:
+		HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
+		break;
+	case S2:
+		HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
+		break;
+	case S3:
+		HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
+		break;
+	case S4:
+		HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
+		break;
+	case S5:
+		HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
+		break;
+	case S6:
+		HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);
+		break;
+	case S7:
+		HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);
+		break;
+	case S8:
+		HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
+		break;
+	case S9:
+		HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4);
+		break;
+	}
+}
+
+uint16_t PourcentageToValue(uint8_t val){
+	HAL_Delay(1);
+	return (uint16_t)val * PWM_MAX;
+}
+
+uint8_t PWMPourcentage(Heure *heure, Sortie *sortie){
+	Heure hd,he;
+
+	HeureAjout(hd,sortie->Demmarage,sortie->Pente);
+	HeureSuppr(he,sortie->Extinxtion,sortie->Pente);
+
+	if ((CompareHeure(*heure,sortie->Demmarage)>=0) & (CompareHeure(*heure,hd)<0)){
+		return (DiffHeure(*heure,sortie->Demmarage)/sortie->Pente)*sortie->PuissanceMax;
+	}
+	else if ((CompareHeure(*heure,hd)>=0) &(CompareHeure(*heure,he)<=0)){
+		return sortie->PuissanceMax;
+	}
+	else if ((CompareHeure(*heure,hd)>0) & (CompareHeure(*heure,sortie->Extinxtion)<=0)){
+		return (DiffHeure(sortie->Extinxtion,*heure)/sortie->Pente)*sortie->PuissanceMax;
+	}
+	else{
+		return 0;
+	}
+}

+ 73 - 0
Source/RTC.c

@@ -0,0 +1,73 @@
+/*
+ * RTC.c
+ *
+ *  Created on: 15 janv. 2019
+ *      Author: e_rcluze
+ */
+
+#include "RTC.h"
+#include "i2c.h"
+
+void readHeure(Heure *heure){
+	uint8_t tab[2];
+	readRTC(MINUTES,tab,2);
+	heure->minute = (((tab[0]&0x70)>>4)*10)+(tab[0]&0X0F);
+	heure->heure = (((tab[1]&0X30)>>4)*10)+(tab[1]&0X0F);
+}
+
+void readDate(Date *date){
+	uint8_t tab[7];
+	readRTC(SECOND,tab,7);
+	//uint8_t sec10 = (((tab[0]&0X70)>>4)*10);
+	//uint8_t	sec =  tab[0]&0X0F;
+	date->second=(((tab[0]&0X70)>>4)*10)+(tab[0]&0X0F);
+	date->minute=(((tab[1]&0x70)>>4)*10)+(tab[1]&0X0F);
+	date->heure=(((tab[2]&0X30)>>4)*10)+(tab[2]&0X0F);
+	date->jour=(((tab[4]&0X30)>>4)*10)+(tab[4]&0X0F);
+	date->mois=(((tab[5]&0X10)>>4)*10)+(tab[5]&0X0F);
+	date->annee=((tab[6]>>4)*10)+(tab[6]&0X0F);
+}
+
+void WriteDate(Date *date){
+	uint8_t tab[7];
+
+	tab[0]=((date->second/10)<<4) + (date->second%10);
+	tab[1]=((date->minute/10)<<4) + (date->minute%10);
+	tab[2]=((date->heure/10)<<4) + (date->heure%10);
+	tab[3]=date->joursemaine;
+	tab[4]=((date->jour/10)<<4) + (date->jour%10);
+	tab[5]=((date->mois/10)<<4) + (date->mois%10);
+	tab[6]=((date->annee/10)<<4) + (date->annee%10);
+
+	writeRTC(SECOND,tab,7);
+}
+
+void redemareRTC(){
+	uint8_t pt[1];
+	readRTC(ALARM_HOURS,pt,1);
+	pt[0]=pt[0]&!0x40;
+	writeRTC(ALARM_HOURS,pt,1);
+}
+
+void testRTC(){
+	Date d;
+	d.annee=2020;
+	d.mois=1;
+	d.jour=20;
+	d.joursemaine=1;
+	d.heure=14;
+	d.minute=0;
+	d.second=0;
+	writeDate(&d);
+	redemareRTC();
+	HAL_Delay(2000);
+	readDate(d);
+	HAL_Delay(1);
+}
+
+void testBatteryRTC(){
+	redemareRTC();
+	Date d;
+	readDate(d);
+	HAL_Delay(1);
+}