Line data Source code
1 : #include "wibmod/WIB1/WIB.hh"
2 : #include "wibmod/WIB1/WIBException.hh"
3 :
4 0 : uint32_t WIB::ReadLocalFlash(uint16_t address){
5 : //load the address
6 0 : Write("SYSTEM.FLASH.ADDRESS",address);
7 : //start the read transaction
8 0 : Write("SYSTEM.FLASH.RW",1);
9 0 : Write("SYSTEM.FLASH.RUN",1);
10 :
11 : //Wait for transaction to finish
12 0 : while(Read("SYSTEM.FLASH.DONE") == 0){
13 0 : printf("busy\n");
14 : //sleep for 1ms
15 0 : usleep(1000);
16 : }
17 :
18 0 : return Read("SYSTEM.FLASH.RD_DATA");
19 : }
20 :
21 0 : std::vector<uint32_t> WIB::ReadLocalFlash(uint16_t address,size_t n){
22 0 : std::vector<uint32_t> readData;
23 0 : size_t current_address = address;
24 0 : size_t end_address = current_address + n;
25 0 : for(;current_address < end_address;current_address++){
26 0 : readData.push_back(ReadLocalFlash(current_address));
27 : }
28 0 : return readData;
29 0 : }
30 :
31 :
32 0 : void WIB::WriteLocalFlash(uint16_t address, uint32_t data){
33 : //load the address
34 0 : Write("SYSTEM.FLASH.ADDRESS",address);
35 : //load the data to write
36 0 : Write("SYSTEM.FLASH.WR_DATA",data);
37 :
38 : //start the read transaction
39 0 : Write("SYSTEM.FLASH.RW",0);
40 0 : Write("SYSTEM.FLASH.RUN",1);
41 : //Wait for finish
42 0 : while(Read("SYSTEM.FLASH.DONE") == 0){
43 : //sleep for 1ms
44 0 : usleep(1000);
45 : }
46 0 : }
47 :
48 :
49 0 : void WIB::WriteLocalFlash(uint16_t address,std::vector<uint32_t> const & data){
50 0 : for(size_t iWord = 0; iWord < data.size();iWord++){
51 0 : WriteLocalFlash(address,data[iWord]);
52 0 : address++;
53 : }
54 0 : }
|