Milos RTOS v0.3.4a
Real Time Operating System
m24ctest/main.c
Go to the documentation of this file.
00001 #include <core/system.h>
00002 #include <core/thread.h>
00003 #include <core/device.h>
00004 #include <core/dbgterm.h>
00005 #include <common/mem.h>
00006 
00007 u8 buf[128];
00008 u8 read[32];
00009 
00010 __VOID appThread1(__VOID)
00011 {
00012 
00013     u16 i = 0;
00014     u16 address = 0;
00015     u16 pages;
00016 
00017     /* Find the M24CXX device */
00018     __PDEVICE dv = __deviceFind("m24c1");
00019     if (!dv) goto ERROR;
00020 
00021     /* Initialize and open the M24C device (it will open with the default
00022      * board/platform values). */
00023     __deviceInit(dv, __NULL, 0);
00024     __deviceOpen(dv, 0);
00025 
00026     /*
00027      * Get the quantity of pages.
00028      */
00029     pages = __deviceIOCtl(dv, __IOCTL_GET_MAX_PAGES, 0, __NULL, 0);
00030 
00031     for (i = 0; i < 32; i++)
00032     {
00033         buf[i] = i;
00034     }
00035 
00036     /*
00037      * Write every page.
00038      */
00039     DBGMSG(1, ("\r\nWrite test. %lu pages.\r\n", (u32) pages));
00040 
00041     for (i = 0; i < pages; i++)
00042     {
00043         /* Set the page number */
00044         __deviceIOCtl(dv, __IOCTL_SET_PAGE, i, __NULL, 0);
00045 
00046         /* Write */
00047         if (__deviceWrite(dv, buf, 32) != 32)
00048         {
00049             DBGMSG(1, ("Error writing page %lu", (u32) i));
00050             goto ERROR;
00051         } else {
00052             DBGMSG(1, ("Write OK page %lu", (u32) i));
00053         }
00054 
00055         /* Write time is 10ms */
00056         __threadSleep(10);
00057     }
00058 
00059     DBGMSG(1, ("\r\nRead test. %lu pages.\r\n", (u32) pages));
00060 
00061     /*
00062      * Read every page and check content.
00063      */
00064     for (i = 0; i < pages; i++)
00065     {
00066         /* Set the page number */
00067         __deviceIOCtl(dv, __IOCTL_SET_PAGE, i, __NULL, 0);
00068 
00069         __memSet(read, 0, 32);
00070 
00071         /* Read */
00072         if (__deviceRead(dv, read, 32) != 32)
00073         {
00074             DBGMSG(1, ("Error reading page %lu", (u32) i));
00075         } else {
00076             DBGMSG(1, ("Read OK page %lu", (u32) i));
00077 
00078             if (__memCmp(buf, read, 32) != 0)
00079             {
00080                 DBGMSG(1, ("Memory compare failed page %lu", (u32) i));
00081                 goto ERROR;
00082             } else {
00083                 DBGMSG(1, ("Memory compare OK page %lu", (u32) i));
00084             }
00085         }
00086     }
00087 
00088     /*
00089      * Random byte write/read
00090      */
00091     for (i = 0; i < pages; i++)
00092     {
00093         address = __systemGetTickCount() & 0xFFFF;
00094         __deviceIOCtl(dv, __IOCTL_SET_ADDRESS, address, __NULL, 0);
00095 
00096         DBGMSG(1, ("\r\nRandom write byte 0xAB at address %lu", (u32) address));
00097         buf[0] = 0xAB;
00098 
00099         if (__deviceWrite(dv, buf, 1) == 1)
00100         {
00101             DBGMSG(1, ("Random write OK"));
00102 
00103             /* Write time is 10ms */
00104             __threadSleep(10);
00105 
00106             read[0] = 0;
00107 
00108             __deviceRead(dv, read, 1);
00109             if (read[0] == 0xAB)
00110             {
00111                 DBGMSG(1, ("Random read OK"));
00112             } else goto ERROR;
00113         } else goto ERROR;
00114     }
00115 
00116 ERROR:
00117     for (;;)
00118     {
00119 
00120     }
00121 }
00122 
00126 __VOID appEntry(__VOID)
00127 {
00128     __threadCreate("app1", appThread1, 100, 1024, 1, __NULL);
00129 }
00130 
00134 int main(void)
00135 {
00136     __systemInit(appEntry);
00137     return 0;
00138 }
 All Data Structures Files Functions Variables Typedefs Defines