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