-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlasherClient.cpp
More file actions
129 lines (112 loc) · 3.31 KB
/
FlasherClient.cpp
File metadata and controls
129 lines (112 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//------------------------------------------------------------------------
// Copyright(c) 2024 Dad Design.
//
// Utilitaire pour flasher la mémoire QSPIFlash à partir d'un PC
// Partie cliente
//-----------------------------------------------------------------------
#include "daisy_seed.h"
#include "Flasher.h"
#include "Buff.h"
//#pragma GCC optimize ("O0")
using namespace daisy;
#define VAL_TIMEOUT 100
// Variables globales
DaisySeed hw;
Dad::stQSPI DSY_QSPI_BSS __QSPI;
Dad::cBuff ___DataBuff(sizeof(Dad::Bloc)*2);
uint8_t DSY_SDRAM_BSS __PageBuff[NB_BLOC_TRANS][TAILLE_BLOC_TRANS];
// Reception des données lues sur la liaison serie USB (COMxx)
void UsbCallback(uint8_t* buf, uint32_t* len)
{
uint8_t* pBuff = buf;
for(uint32_t Index=*len; Index != 0; Index--){
___DataBuff.addData(*pBuff++);
}
}
// Traitement d'un bloc
bool BlocProcess(uint16_t NumBloc){
Dad::Bloc* pBloc = (Dad::Bloc*)___DataBuff.getBuffPtr();
// Test validité du bloc
if((pBloc->StartMarker[0] != 'B') ||
(pBloc->StartMarker[1] != 'L') ||
(pBloc->StartMarker[2] != 'O') ||
(pBloc->StartMarker[3] != 'C') ||
(pBloc->EndMarker[0] != 'E') ||
(pBloc->EndMarker[1] != 'N') ||
(pBloc->EndMarker[2] != 'D') ||
(NumBloc != pBloc->NumBloc)
)
{
return false;
}
// Copie du bloc dans la mémoire de page et calcul du CRC
uint8_t* pPageBuff = __PageBuff[NumBloc%NB_BLOC_TRANS];
uint8_t* pBlocData = pBloc->Data;
uint8_t CalcCRC = 0;
for(uint16_t Index = 0; Index < TAILLE_BLOC_TRANS; Index++){
CalcCRC += *pBlocData;
*pPageBuff++ = *pBlocData++;
}
if(CalcCRC != pBloc->_CRC){
return false;
}
// test fin de page -> Flash la page
if(((NumBloc%NB_BLOC_TRANS)==(NB_BLOC_TRANS-1)) || (pBloc->_EndTrans != 0)){
uint16_t NumPage = NumBloc/NB_BLOC_TRANS;
uint32_t adresseData = (uint32_t) &__QSPI.Data[NumPage];
hw.qspi.Erase(adresseData, adresseData + TAILLE_PAGES_QSPI);
System::Delay(10);
hw.qspi.Write(adresseData, TAILLE_PAGES_QSPI, (uint8_t*)__PageBuff);
System::Delay(10);
// Vérification
uint8_t * pQSPI = (uint8_t*) __QSPI.Data[NumPage];
uint8_t * pPageBuff = (uint8_t*) __PageBuff;
for (uint16_t Index = 0 ; Index < TAILLE_PAGES_QSPI; Index++){
if(*pPageBuff++ != *pQSPI++){
return false;
}
}
}
if(pBloc->_EndTrans != 0){
return false;
}else{
return true;
}
}
int main(void)
{
hw.Init();
hw.usb_handle.Init(UsbHandle::FS_INTERNAL);
System::Delay(500);
hw.usb_handle.SetReceiveCallback(UsbCallback, UsbHandle::FS_INTERNAL);
uint16_t NumBloc = 0;
Dad::MsgClient Msg;
bool ResultProcess=false;
Msg.StartMarker[0] = 'B';Msg.StartMarker[1] = 'L';Msg.StartMarker[2] = 'O';Msg.StartMarker[3] = 'C';
while(1) {
// Si erreur on retourne au premier bloc sinon bloc suivant
if(ResultProcess == false){
NumBloc = 0;
hw.SetLed(true);
}else{
NumBloc++;
}
// Emission d'un message vers le serveur
___DataBuff.Clear();
Msg.NumBloc = NumBloc;
hw.usb_handle.TransmitInternal((uint8_t *)&Msg, sizeof(Msg));
// Attente transmission d'un bloc
uint16_t TimeOut = 0;
while(___DataBuff.getNbData()<sizeof(Dad::Bloc) && (TimeOut<VAL_TIMEOUT)){
TimeOut++;
System::Delay(10);
}
// Traitement du bloc
if(TimeOut<VAL_TIMEOUT){
hw.SetLed(false);
ResultProcess = BlocProcess(NumBloc);
}else{
ResultProcess = false;
}
}
}