mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/spifi1/main.cpp@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "test_env.h" |
elessair | 0:f269e3021894 | 2 | #include "mbed.h" |
elessair | 0:f269e3021894 | 3 | #include "spifi_rom_api.h" |
elessair | 0:f269e3021894 | 4 | |
elessair | 0:f269e3021894 | 5 | __attribute__((section("SPIFI_MEM"))) const unsigned char cube_image[] = { |
elessair | 0:f269e3021894 | 6 | 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82, |
elessair | 0:f269e3021894 | 7 | 0,0,0,150,0,0,0,200,8,2,0,0,0,133,231,143, |
elessair | 0:f269e3021894 | 8 | 50,0,0,0,1,115,82,71,66,0,174,206,28,233,0,0, |
elessair | 0:f269e3021894 | 9 | 0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0, |
elessair | 0:f269e3021894 | 10 | 0,9,112,72,89,115,0,0,14,195,0,0,14,195,1,199, |
elessair | 0:f269e3021894 | 11 | 111,168,100,0,0,156,193,73,68,65,84,120,94,236,253,103, |
elessair | 0:f269e3021894 | 12 | 124,27,233,125,54,140,14,48,24,0,51,24,244,94,9,246, |
elessair | 0:f269e3021894 | 13 | 0,0,0,0,73,69,78,68,174,66,96,130}; |
elessair | 0:f269e3021894 | 14 | |
elessair | 0:f269e3021894 | 15 | int cube_image_sz = sizeof(cube_image); |
elessair | 0:f269e3021894 | 16 | |
elessair | 0:f269e3021894 | 17 | const unsigned char cube_image_ref[] = { |
elessair | 0:f269e3021894 | 18 | 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82, |
elessair | 0:f269e3021894 | 19 | 0,0,0,150,0,0,0,200,8,2,0,0,0,133,231,143, |
elessair | 0:f269e3021894 | 20 | 50,0,0,0,1,115,82,71,66,0,174,206,28,233,0,0, |
elessair | 0:f269e3021894 | 21 | 0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0, |
elessair | 0:f269e3021894 | 22 | 0,9,112,72,89,115,0,0,14,195,0,0,14,195,1,199, |
elessair | 0:f269e3021894 | 23 | 111,168,100,0,0,156,193,73,68,65,84,120,94,236,253,103, |
elessair | 0:f269e3021894 | 24 | 124,27,233,125,54,140,14,48,24,0,51,24,244,94,9,246, |
elessair | 0:f269e3021894 | 25 | 0,0,0,0,73,69,78,68,174,66,96,130}; |
elessair | 0:f269e3021894 | 26 | |
elessair | 0:f269e3021894 | 27 | int cube_image_ref_sz = sizeof(cube_image_ref); |
elessair | 0:f269e3021894 | 28 | |
elessair | 0:f269e3021894 | 29 | /* |
elessair | 0:f269e3021894 | 30 | * The SPIFI_ROM_PTR (0x1FFF1FF8) points to an area where the pointers to |
elessair | 0:f269e3021894 | 31 | * different drivers in ROM are stored. |
elessair | 0:f269e3021894 | 32 | */ |
elessair | 0:f269e3021894 | 33 | typedef struct { |
elessair | 0:f269e3021894 | 34 | /*const*/ unsigned p_usbd; // USBROMD |
elessair | 0:f269e3021894 | 35 | /*const*/ unsigned p_clib; |
elessair | 0:f269e3021894 | 36 | /*const*/ unsigned p_cand; |
elessair | 0:f269e3021894 | 37 | /*const*/ unsigned p_pwrd; // PWRROMD |
elessair | 0:f269e3021894 | 38 | /*const*/ unsigned p_promd; // DIVROMD |
elessair | 0:f269e3021894 | 39 | /*const*/ SPIFI_RTNS *pSPIFID; // SPIFIROMD |
elessair | 0:f269e3021894 | 40 | /*const*/ unsigned p_dev3; |
elessair | 0:f269e3021894 | 41 | /*const*/ unsigned p_dev4; |
elessair | 0:f269e3021894 | 42 | } ROM; |
elessair | 0:f269e3021894 | 43 | |
elessair | 0:f269e3021894 | 44 | #define ROM_DRIVERS_PTR ((ROM *)(*((unsigned int *)SPIFI_ROM_PTR))) |
elessair | 0:f269e3021894 | 45 | #define IS_ADDR_IN_SPIFI(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == SPIFI_MEM_BASE ) |
elessair | 0:f269e3021894 | 46 | #define IS_ADDR_IN_IFLASH(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == 0x10000000 ) |
elessair | 0:f269e3021894 | 47 | |
elessair | 0:f269e3021894 | 48 | static void initialize_spifi(void) |
elessair | 0:f269e3021894 | 49 | { |
elessair | 0:f269e3021894 | 50 | SPIFIobj* obj = (SPIFIobj*)malloc(sizeof(SPIFIobj)); |
elessair | 0:f269e3021894 | 51 | if (obj == NULL) { |
elessair | 0:f269e3021894 | 52 | // Failed to allocate memory for ROM data |
elessair | 0:f269e3021894 | 53 | notify_completion(false); |
elessair | 0:f269e3021894 | 54 | } |
elessair | 0:f269e3021894 | 55 | |
elessair | 0:f269e3021894 | 56 | // Turn on SPIFI block as it is disabled on reset |
elessair | 0:f269e3021894 | 57 | LPC_SC->PCONP |= 0x00010000; |
elessair | 0:f269e3021894 | 58 | |
elessair | 0:f269e3021894 | 59 | // pinsel for SPIFI |
elessair | 0:f269e3021894 | 60 | LPC_IOCON->P2_7 = 5; /* SPIFI_CSN @ P2.7 */ |
elessair | 0:f269e3021894 | 61 | LPC_IOCON->P0_22 = 5; /* SPIFI_CLK @ P0.22 */ |
elessair | 0:f269e3021894 | 62 | LPC_IOCON->P0_15 = 5; /* SPIFI_IO2 @ P0.15 */ |
elessair | 0:f269e3021894 | 63 | LPC_IOCON->P0_16 = 5; /* SPIFI_IO3 @ P0.16 */ |
elessair | 0:f269e3021894 | 64 | LPC_IOCON->P0_17 = 5; /* SPIFI_IO1 @ P0.17 */ |
elessair | 0:f269e3021894 | 65 | LPC_IOCON->P0_18 = 5; /* SPIFI_IO0 @ P0.18 */ |
elessair | 0:f269e3021894 | 66 | |
elessair | 0:f269e3021894 | 67 | uint32_t spifi_clk_div = (*((volatile uint32_t*)0x400FC1B4)) & 0x1f; |
elessair | 0:f269e3021894 | 68 | uint32_t spifi_clk_mhz = (SystemCoreClock / spifi_clk_div) / 1000000; |
elessair | 0:f269e3021894 | 69 | |
elessair | 0:f269e3021894 | 70 | const SPIFI_RTNS* _spifi = ROM_DRIVERS_PTR->pSPIFID; |
elessair | 0:f269e3021894 | 71 | |
elessair | 0:f269e3021894 | 72 | /* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */ |
elessair | 0:f269e3021894 | 73 | int rc = _spifi->spifi_init (obj, spifi_clk_mhz/5, S_FULLCLK+S_RCVCLK, spifi_clk_mhz); |
elessair | 0:f269e3021894 | 74 | if (rc) { |
elessair | 0:f269e3021894 | 75 | // Failed to initialize SPIFI |
elessair | 0:f269e3021894 | 76 | notify_completion(false); |
elessair | 0:f269e3021894 | 77 | } |
elessair | 0:f269e3021894 | 78 | } |
elessair | 0:f269e3021894 | 79 | |
elessair | 0:f269e3021894 | 80 | int main() { |
elessair | 0:f269e3021894 | 81 | |
elessair | 0:f269e3021894 | 82 | initialize_spifi(); |
elessair | 0:f269e3021894 | 83 | |
elessair | 0:f269e3021894 | 84 | // Make sure that cube_image is placed in SPIFI |
elessair | 0:f269e3021894 | 85 | if (!IS_ADDR_IN_SPIFI(cube_image)) { |
elessair | 0:f269e3021894 | 86 | notify_completion(false); |
elessair | 0:f269e3021894 | 87 | } |
elessair | 0:f269e3021894 | 88 | |
elessair | 0:f269e3021894 | 89 | // Make sure that cube_image_ref is in IFLASH |
elessair | 0:f269e3021894 | 90 | if (IS_ADDR_IN_SPIFI(cube_image_ref)) { |
elessair | 0:f269e3021894 | 91 | notify_completion(false); |
elessair | 0:f269e3021894 | 92 | } |
elessair | 0:f269e3021894 | 93 | |
elessair | 0:f269e3021894 | 94 | // Compare content |
elessair | 0:f269e3021894 | 95 | if (cube_image_sz != cube_image_ref_sz) { |
elessair | 0:f269e3021894 | 96 | notify_completion(false); |
elessair | 0:f269e3021894 | 97 | } else { |
elessair | 0:f269e3021894 | 98 | int i = 0; |
elessair | 0:f269e3021894 | 99 | for (; i < cube_image_sz; i++) { |
elessair | 0:f269e3021894 | 100 | if (cube_image[i] != cube_image_ref[i]) { |
elessair | 0:f269e3021894 | 101 | notify_completion(false); |
elessair | 0:f269e3021894 | 102 | } |
elessair | 0:f269e3021894 | 103 | } |
elessair | 0:f269e3021894 | 104 | } |
elessair | 0:f269e3021894 | 105 | |
elessair | 0:f269e3021894 | 106 | notify_completion(true); |
elessair | 0:f269e3021894 | 107 | } |