aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bossac/src/D5xNvmFlash.h
blob: d266f588697de08189098e5137f0f861f3ef6dd3 (plain)
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
///////////////////////////////////////////////////////////////////////////////
// BOSSA
//
// Copyright (c) 2018, ShumaTech
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////////////

#ifndef _D5XNVMFLASH_H
#define _D5XNVMFLASH_H

#include <stdint.h>
#include <exception>

#include "Flash.h"

class D5xNvmFlash : public Flash
{
public:
    D5xNvmFlash(
        Samba& samba,
        const std::string& name,
        uint32_t pages,
        uint32_t size,
        uint32_t user,
        uint32_t stack);

    virtual ~D5xNvmFlash();

    void eraseAll(uint32_t offset);
    void eraseAuto(bool enable);

    std::vector<bool> getLockRegions();

    bool getSecurity();

    bool getBod();
    bool canBod() { return true; }

    bool getBor();
    bool canBor() { return true; }

    bool getBootFlash();
    bool canBootFlash() { return false; }

    void writeOptions();

    void writePage(uint32_t page);
    void readPage(uint32_t page, uint8_t* data);

    void writeBuffer(uint32_t dst_addr, uint32_t size);

protected:
    bool     _eraseAuto;

    uint16_t readRegU16(uint8_t reg);
    void writeRegU16(uint8_t reg, uint16_t value);
    uint32_t readRegU32(uint8_t reg);
    void writeRegU32(uint8_t reg, uint32_t value);

    void waitReady();
    void command(uint8_t cmd);
    void erase(uint32_t offset, uint32_t size);
    void checkError();
    void readUserPage(std::unique_ptr<uint8_t[]>& userPage);
};

#endif // _D5XNVMFLASH_H