-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmegaMain.cpp
More file actions
164 lines (146 loc) · 5.04 KB
/
megaMain.cpp
File metadata and controls
164 lines (146 loc) · 5.04 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/******************************************************************************/
/**
* @file megaMain.cpp
* @author EmbedDB Team (See Authors.md)
* @brief Main Arduino program for testing EmbedDB implementation on custom hardware.
* @copyright Copyright 2024
* EmbedDB Team
* @par Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* @par 1.Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* @par 2.Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* @par 3.Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* @par THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************************************************/
#ifndef PIO_UNIT_TESTING
#include "Arduino.h"
#include "SPI.h"
/**
* Includes for SD card
*/
/** @TODO optimize for clock speed */
#include "sdios.h"
static ArduinoOutStream cout(Serial);
#include <math.h>
#include "SdFat.h"
#include "sd_test.h"
#include "sdcard_c_iface.h"
#include "serial_c_iface.h"
/**
* 0 - 2 are for benchmarks
* 3 is for the example program
*
*/
#ifndef WHICH_PROGRAM
#define WHICH_PROGRAM 0
#endif
#if WHICH_PROGRAM == 0
#include "embedDBExample.h"
#elif WHICH_PROGRAM == 1
#include "benchmarks/sequentialDataBenchmark.h"
#elif WHICH_PROGRAM == 2
#include "benchmarks/variableDataBenchmark.h"
#elif WHICH_PROGRAM == 3
#include "benchmarks/queryInterfaceBenchmark.h"
#endif
#define ENABLE_DEDICATED_SPI 1
#define SD_FAT_TYPE 1
/** @TODO Update max SPI speed for SD card */
const uint8_t SD_CS_PIN = SS;
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(12))
SdFat32 sd;
File32 file;
// Headers
bool test_sd_card();
void setup() {
Serial.begin(9600);
while (!Serial) {
delay(1);
}
delay(1000);
Serial.println("Skeleton startup");
/* Setup for SD card */
Serial.print("\nInitializing SD card...");
if (test_sd_card()) {
file = sd.open("/");
cout << F("\nList of files on the SD.\n");
sd.ls("/", LS_R);
}
init_sdcard((void *)&sd);
#if WHICH_PROGRAM == 0
embedDBExample();
#elif WHICH_PROGRAM == 1
runalltests_embedDB();
#elif WHICH_PROGRAM == 2
test_vardata();
#elif WHICH_PROGRAM == 3
advancedQueryExample();
#endif
}
void loop() {
// Serial.println("Finished\n");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
/**
* Testing for SD card -> Can be removed as needed */
bool test_sd_card() {
if (!sd.cardBegin(SD_CONFIG)) {
Serial.println(F(
"\nSD initialization failed.\n"
"Do not reformat the card!\n"
"Is the card correctly inserted?\n"
"Is there a wiring/soldering problem?\n"));
if (isSpi(SD_CONFIG)) {
Serial.println(F(
"Is SD_CS_PIN set to the correct value?\n"
"Does another SPI device need to be disabled?\n"));
}
errorPrint(sd);
return false;
}
if (!sd.card()->readCID(&m_cid) ||
!sd.card()->readCSD(&m_csd) ||
!sd.card()->readOCR(&m_ocr)) {
cout << F("readInfo failed\n");
errorPrint(sd);
}
printCardType(sd);
cidDmp();
csdDmp();
cout << F("\nOCR: ") << uppercase << showbase;
cout << hex << m_ocr << dec << endl;
if (!mbrDmp(sd)) {
return false;
}
if (!sd.volumeBegin()) {
cout << F("\nvolumeBegin failed. Is the card formatted?\n");
errorPrint(sd);
return false;
}
dmpVol(sd);
return true;
}
#endif