dataflash_hwtest.c
Go to the documentation of this file.00001
00050 #include "hw/hw_dataflash.h"
00051 #include "cfg/cfg_dataflash.h"
00052 #include "cfg/cfg_proc.h"
00053
00054 #include <cfg/test.h>
00055 #include <cfg/debug.h>
00056 #include <cfg/module.h>
00057
00058
00059 #define LOG_LEVEL DATAFLASH_LOG_LEVEL
00060 #define LOG_FORMAT DATAFLASH_LOG_FORMAT
00061 #include <cfg/log.h>
00062
00063 #include <drv/timer.h>
00064 #include <drv/ser.h>
00065 #include <drv/dataflash.h>
00066
00067 #include <kern/proc.h>
00068 #include <io/kfile.h>
00069
00070 #include <string.h>
00071
00072
00073
00074
00075
00076
00077
00078 #define DATAFLASH_MEM_MODEL DFT_AT45DB642D
00079
00080
00081 #define DATAFLASH_FUNC_CS_SET dataflash_hw_setCS
00082
00083
00084 #define DATAFLASH_FUNC_RESET NULL
00085
00086
00087 #define DATAFLASH_TEST_STR_LEN 12307
00088
00089
00090 #define DATAFLASH_USE_RAND_FUNC 0
00091
00092
00093
00094
00095
00096 static Serial spi_fd;
00097 static DataFlash dflash_fd;
00098
00099
00100
00101
00102
00103 static uint8_t test_buf[DATAFLASH_TEST_STR_LEN];
00104 static uint8_t save_buf[DATAFLASH_TEST_STR_LEN];
00105
00110 int dataflash_testSetup(void)
00111 {
00112 kfile_testSetup();
00113 LOG_INFO("KFILE setup..ok\n");
00114
00115 LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n");
00116 SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN");
00117 ASSERT(!CONFIG_KERN);
00118
00119
00120
00121
00122
00123 MOD_CHECK(kfile_test);
00124
00125 timer_init();
00126 LOG_INFO("Timer init..ok\n");
00127
00128
00129
00130
00131
00132 spimaster_init(&spi_fd, 0);
00133 LOG_INFO("SPI0 init..ok\n");
00134
00135 ser_setbaudrate(&spi_fd, 5000000UL);
00136 LOG_INFO("SPI0 set baudrate..ok\n");
00137
00138
00139 dataflash_hw_init();
00140 LOG_INFO("DATAFLASH HW..ok\n");
00141
00142 if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET))
00143 LOG_INFO("DATAFLASH init..ok\n");
00144 else
00145 LOG_ERR("DATAFLASH init..fail\n");
00146
00147
00148
00149 for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++)
00150 {
00151 #if DATAFLASH_USE_RAND_FUNC
00152 #include <stdlib.h>
00153
00154 test_buf[i] = (uint8_t)rand();
00155 #else
00156 test_buf[i] = (i & 0xff);
00157 #endif
00158 }
00159
00160 LOG_INFO("Fill tmp buff..ok\n");
00161
00162 return 0;
00163 }
00164
00165
00170 int dataflash_testRun(void)
00171 {
00172 LOG_INFO("Run KFILE test.\n");
00173
00174 SILENT_ASSERT("bertos/drv/dataflash.c:405: Assertion failed: fd->fd.seek_pos + size <= fd->fd.size");
00175 if (kfile_testRunGeneric(&dflash_fd.fd, test_buf, save_buf, sizeof(test_buf)) != EOF)
00176 {
00177 LOG_INFO("KFILE test..ok\n");
00178 }
00179 else
00180 {
00181 LOG_ERR("KFILE test..fail!\n");
00182 return EOF;
00183 }
00184
00185 return 0;
00186 }
00187
00192 int dataflash_testTearDown(void)
00193 {
00194
00195 return 0;
00196 }
00197
00198
00199
00200
00201
00202
00203
00204 #if 0
00205 int main(void)
00206 {
00207 IRQ_ENABLE;
00208 kdbg_init();
00209
00210 #if CONFIG_KERN
00211 proc_init();
00212 #endif
00213
00214 if (!dataflash_testSetup())
00215 {
00216 LOG_INFO("DATAFLASH setup..ok\n");
00217 }
00218 else
00219 {
00220 LOG_ERR("DATAFLASH setup..fail!\n");
00221 return EOF;
00222 }
00223
00224 dataflash_testRun();
00225
00226 for(;;)
00227 {
00228 }
00229 }
00230 #endif