1 ///////////////////////////////////////////////////////////////////////////////
2 // BOSSA
3 //
4 // Copyright (c) 2011-2018, ShumaTech
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //     * Redistributions of source code must retain the above copyright
10 //       notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above copyright
12 //       notice, this list of conditions and the following disclaimer in the
13 //       documentation and/or other materials provided with the distribution.
14 //     * Neither the name of the <organization> nor the
15 //       names of its contributors may be used to endorse or promote products
16 //       derived from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ///////////////////////////////////////////////////////////////////////////////
29 #ifndef _DEVICE_H
30 #define _DEVICE_H
31 
32 #include <exception>
33 
34 #include "Samba.h"
35 #include "Flash.h"
36 
37 class DeviceUnsupportedError : public std::exception
38 {
39 public:
DeviceUnsupportedError()40     DeviceUnsupportedError() : exception() {};
what()41     const char* what() const throw() { return "Device unsupported"; }
42 };
43 
44 class Device
45 {
46 public:
47     enum Family {
48         FAMILY_NONE,
49 
50         FAMILY_SAM7S,
51         FAMILY_SAM7SE,
52         FAMILY_SAM7X,
53         FAMILY_SAM7XC,
54         FAMILY_SAM7L,
55 
56         FAMILY_SAM3N,
57         FAMILY_SAM3S,
58         FAMILY_SAM3U,
59         FAMILY_SAM3X,
60         FAMILY_SAM3A,
61 
62         FAMILY_SAM4S,
63         FAMILY_SAM4E,
64 
65         FAMILY_SAM9XE,
66 
67         FAMILY_SAMD21,
68         FAMILY_SAMR21,
69         FAMILY_SAML21,
70 
71         FAMILY_SAMD51,
72         FAMILY_SAME51,
73         FAMILY_SAME53,
74         FAMILY_SAME54,
75 
76         FAMILY_SAME70,
77         FAMILY_SAMS70,
78         FAMILY_SAMV70,
79         FAMILY_SAMV71,
80     };
81 
Device(Samba & samba)82     Device(Samba& samba) : _samba(samba), _flash(nullptr), _family(FAMILY_NONE) {}
~Device()83     virtual ~Device() {}
84 
85     void create();
86 
getFamily()87     Family getFamily() { return _family; }
88 
89     typedef std::unique_ptr<Flash> const FlashPtr;
90 
getFlash()91     FlashPtr& getFlash() { return _flash; }
92 
93     void reset();
94 
95 private:
96     Samba& _samba;
97     std::unique_ptr<Flash> _flash;
98     Family _family;
99 
100     void readChipId(uint32_t& chipId, uint32_t& extChipId);
101 };
102 
103 #endif // _DEVICE_H
104 
105