mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/spifi2/main.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
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 | extern const unsigned char splash_image1[]; extern int splash_image1_sz; |
elessair | 0:f269e3021894 | 6 | extern const unsigned char splash_image2[]; extern int splash_image2_sz; |
elessair | 0:f269e3021894 | 7 | extern const unsigned char splash_image3[]; extern int splash_image3_sz; |
elessair | 0:f269e3021894 | 8 | extern const unsigned char splash_image4[]; extern int splash_image4_sz; |
elessair | 0:f269e3021894 | 9 | extern const unsigned char splash_image5[]; extern int splash_image5_sz; |
elessair | 0:f269e3021894 | 10 | extern const unsigned char splash_image6[]; extern int splash_image6_sz; |
elessair | 0:f269e3021894 | 11 | extern const unsigned char splash_image7[]; extern int splash_image7_sz; |
elessair | 0:f269e3021894 | 12 | extern const unsigned char splash_image8[]; extern int splash_image8_sz; |
elessair | 0:f269e3021894 | 13 | extern const unsigned char splash_image9[]; extern int splash_image9_sz; |
elessair | 0:f269e3021894 | 14 | extern const unsigned char splash_image10[]; extern int splash_image10_sz; |
elessair | 0:f269e3021894 | 15 | extern const unsigned char splash_image11[]; extern int splash_image11_sz; |
elessair | 0:f269e3021894 | 16 | extern const unsigned char splash_image12[]; extern int splash_image12_sz; |
elessair | 0:f269e3021894 | 17 | extern const unsigned char splash_image13[]; extern int splash_image13_sz; |
elessair | 0:f269e3021894 | 18 | extern const unsigned char splash_image14[]; extern int splash_image14_sz; |
elessair | 0:f269e3021894 | 19 | extern const unsigned char splash_image15[]; extern int splash_image15_sz; |
elessair | 0:f269e3021894 | 20 | |
elessair | 0:f269e3021894 | 21 | /* |
elessair | 0:f269e3021894 | 22 | * The SPIFI_ROM_PTR (0x1FFF1FF8) points to an area where the pointers to |
elessair | 0:f269e3021894 | 23 | * different drivers in ROM are stored. |
elessair | 0:f269e3021894 | 24 | */ |
elessair | 0:f269e3021894 | 25 | typedef struct { |
elessair | 0:f269e3021894 | 26 | /*const*/ unsigned p_usbd; // USBROMD |
elessair | 0:f269e3021894 | 27 | /*const*/ unsigned p_clib; |
elessair | 0:f269e3021894 | 28 | /*const*/ unsigned p_cand; |
elessair | 0:f269e3021894 | 29 | /*const*/ unsigned p_pwrd; // PWRROMD |
elessair | 0:f269e3021894 | 30 | /*const*/ unsigned p_promd; // DIVROMD |
elessair | 0:f269e3021894 | 31 | /*const*/ SPIFI_RTNS *pSPIFID; // SPIFIROMD |
elessair | 0:f269e3021894 | 32 | /*const*/ unsigned p_dev3; |
elessair | 0:f269e3021894 | 33 | /*const*/ unsigned p_dev4; |
elessair | 0:f269e3021894 | 34 | } ROM; |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | #define ROM_DRIVERS_PTR ((ROM *)(*((unsigned int *)SPIFI_ROM_PTR))) |
elessair | 0:f269e3021894 | 37 | #define IS_ADDR_IN_SPIFI(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == SPIFI_MEM_BASE ) |
elessair | 0:f269e3021894 | 38 | #define IS_ADDR_IN_IFLASH(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == 0x10000000 ) |
elessair | 0:f269e3021894 | 39 | |
elessair | 0:f269e3021894 | 40 | static void initialize_spifi(void) |
elessair | 0:f269e3021894 | 41 | { |
elessair | 0:f269e3021894 | 42 | SPIFIobj* obj = (SPIFIobj*)malloc(sizeof(SPIFIobj)); |
elessair | 0:f269e3021894 | 43 | if (obj == NULL) { |
elessair | 0:f269e3021894 | 44 | // Failed to allocate memory for ROM data |
elessair | 0:f269e3021894 | 45 | notify_completion(false); |
elessair | 0:f269e3021894 | 46 | } |
elessair | 0:f269e3021894 | 47 | |
elessair | 0:f269e3021894 | 48 | // Turn on SPIFI block as it is disabled on reset |
elessair | 0:f269e3021894 | 49 | LPC_SC->PCONP |= 0x00010000; |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | // pinsel for SPIFI |
elessair | 0:f269e3021894 | 52 | LPC_IOCON->P2_7 = 5; /* SPIFI_CSN @ P2.7 */ |
elessair | 0:f269e3021894 | 53 | LPC_IOCON->P0_22 = 5; /* SPIFI_CLK @ P0.22 */ |
elessair | 0:f269e3021894 | 54 | LPC_IOCON->P0_15 = 5; /* SPIFI_IO2 @ P0.15 */ |
elessair | 0:f269e3021894 | 55 | LPC_IOCON->P0_16 = 5; /* SPIFI_IO3 @ P0.16 */ |
elessair | 0:f269e3021894 | 56 | LPC_IOCON->P0_17 = 5; /* SPIFI_IO1 @ P0.17 */ |
elessair | 0:f269e3021894 | 57 | LPC_IOCON->P0_18 = 5; /* SPIFI_IO0 @ P0.18 */ |
elessair | 0:f269e3021894 | 58 | |
elessair | 0:f269e3021894 | 59 | uint32_t spifi_clk_div = (*((volatile uint32_t*)0x400FC1B4)) & 0x1f; |
elessair | 0:f269e3021894 | 60 | uint32_t spifi_clk_mhz = (SystemCoreClock / spifi_clk_div) / 1000000; |
elessair | 0:f269e3021894 | 61 | |
elessair | 0:f269e3021894 | 62 | const SPIFI_RTNS* _spifi = ROM_DRIVERS_PTR->pSPIFID; |
elessair | 0:f269e3021894 | 63 | |
elessair | 0:f269e3021894 | 64 | /* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */ |
elessair | 0:f269e3021894 | 65 | int rc = _spifi->spifi_init (obj, spifi_clk_mhz/5, S_FULLCLK+S_RCVCLK, spifi_clk_mhz); |
elessair | 0:f269e3021894 | 66 | if (rc) { |
elessair | 0:f269e3021894 | 67 | // Failed to initialize SPIFI |
elessair | 0:f269e3021894 | 68 | notify_completion(false); |
elessair | 0:f269e3021894 | 69 | } |
elessair | 0:f269e3021894 | 70 | } |
elessair | 0:f269e3021894 | 71 | |
elessair | 0:f269e3021894 | 72 | int main() { |
elessair | 0:f269e3021894 | 73 | |
elessair | 0:f269e3021894 | 74 | initialize_spifi(); |
elessair | 0:f269e3021894 | 75 | |
elessair | 0:f269e3021894 | 76 | // Make sure that most files are placed in IFLASH |
elessair | 0:f269e3021894 | 77 | if (IS_ADDR_IN_SPIFI(splash_image1) || |
elessair | 0:f269e3021894 | 78 | IS_ADDR_IN_SPIFI(splash_image2) || |
elessair | 0:f269e3021894 | 79 | IS_ADDR_IN_SPIFI(splash_image3) || |
elessair | 0:f269e3021894 | 80 | IS_ADDR_IN_SPIFI(splash_image4) || |
elessair | 0:f269e3021894 | 81 | IS_ADDR_IN_SPIFI(splash_image5) || |
elessair | 0:f269e3021894 | 82 | IS_ADDR_IN_SPIFI(splash_image6) || |
elessair | 0:f269e3021894 | 83 | IS_ADDR_IN_SPIFI(splash_image7) || |
elessair | 0:f269e3021894 | 84 | IS_ADDR_IN_SPIFI(splash_image8) || |
elessair | 0:f269e3021894 | 85 | IS_ADDR_IN_SPIFI(splash_image9) || |
elessair | 0:f269e3021894 | 86 | IS_ADDR_IN_SPIFI(splash_image10) || |
elessair | 0:f269e3021894 | 87 | IS_ADDR_IN_SPIFI(splash_image11) || |
elessair | 0:f269e3021894 | 88 | IS_ADDR_IN_SPIFI(splash_image12) || |
elessair | 0:f269e3021894 | 89 | IS_ADDR_IN_SPIFI(splash_image13) || |
elessair | 0:f269e3021894 | 90 | IS_ADDR_IN_SPIFI(splash_image14)) { |
elessair | 0:f269e3021894 | 91 | notify_completion(false); |
elessair | 0:f269e3021894 | 92 | } |
elessair | 0:f269e3021894 | 93 | |
elessair | 0:f269e3021894 | 94 | // Make sure that splash_image15 is placed in SPIFI |
elessair | 0:f269e3021894 | 95 | if (!IS_ADDR_IN_SPIFI(splash_image15)) { |
elessair | 0:f269e3021894 | 96 | notify_completion(false); |
elessair | 0:f269e3021894 | 97 | } |
elessair | 0:f269e3021894 | 98 | |
elessair | 0:f269e3021894 | 99 | notify_completion(true); |
elessair | 0:f269e3021894 | 100 | } |