[691dac]: get_stm8_version.c Maximize Restore History

Download this file

get_stm8_version.c    85 lines (62 with data), 1.3 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
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include "rs232.h"
#include "oggs_app.h"
unsigned char buf[BUFFER_LEN];
void FlushComport()
{
int n;
uint32_t startTime = time(NULL);
double elapsedTime;
do {
n = PollComport(COM_PORT,buf,BUFFER_LEN);
if(n) startTime = time(NULL);
elapsedTime = difftime(time(NULL), startTime);
} while((n > 1) || (elapsedTime < 1));
}
void stm8_reset(int state)
{
if(state)
system("cpm -N STM8_RESET -V 1");
else
system("cpm -N STM8_RESET -V 0");
}
int get_update_info()
{
int n,m;
unsigned char b[65];
uint32_t startTime = time(NULL);
double elapsedTime;
SendByte(COM_PORT, CMD_GETSTATUS | ARG_GETSTATUS_VERSIONINFO );
//read 64 Bytes in 3 s otherwise Timeout
m=0;
do {
n = PollComport(COM_PORT,&b[m],1);
if(n) m+=n;
elapsedTime = difftime(time(NULL), startTime);
} while( (m<64) && (elapsedTime < 3) );
b[64] = 0;
if( m != 64) return 0;
printf("%s",b);
return 1;
}
int main(int argc, char *argv[])
{
int ret;
if(OpenComport(COM_PORT,BAUD_RATE) != 0)
{
fprintf(stderr,"Error opening comport!\n");
return -1;
}
stm8_reset(1);
FlushComport();
stm8_reset(0);
usleep(WAITTIME_AFTERRESET);
ret = get_update_info();
CloseComport(COM_PORT);
return ret;
}