File indexing completed on 2025-05-11 08:23:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <bsp.h>
0018 #include <bsp/bootcard.h>
0019 #include <libcpu/bf537.h>
0020 #include <libcpu/ebiuRegs.h>
0021 #include <libcpu/gpioRegs.h>
0022 #include <libcpu/mmu.h>
0023 #include <libcpu/mmuRegs.h>
0024 #include <libcpu/interrupt.h>
0025 #include <rtems/sysinit.h>
0026
0027 static bfin_mmu_config_t mmuRegions = {
0028
0029 {
0030 {(void *) 0x00000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0031 {(void *) 0x00400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0032 {(void *) 0x00800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0033 {(void *) 0x00c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0034 {(void *) 0x01000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0035 {(void *) 0x01400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0036 {(void *) 0x01800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0037 {(void *) 0x01c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0038 {(void *) 0x02000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0039 {(void *) 0x02400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0040 {(void *) 0x02800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0041 {(void *) 0x02c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0042 {(void *) 0x03000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0043 {(void *) 0x20000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
0044 {(void *) 0xff800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_NOCACHE},
0045 {(void *) 0xffc00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_NOCACHE}
0046 },
0047
0048 {
0049 {(void *) 0x00000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0050 {(void *) 0x00400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0051 {(void *) 0x00800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0052 {(void *) 0x00c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0053 {(void *) 0x01000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0054 {(void *) 0x01400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0055 {(void *) 0x01800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0056 {(void *) 0x01c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0057 {(void *) 0x02000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0058 {(void *) 0x02400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0059 {(void *) 0x02800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0060 {(void *) 0x02c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0061 {(void *) 0x03000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0062 {(void *) 0x20000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
0063 {(void *) 0xff800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_NOCACHE},
0064 {(void *) 0xffc00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_NOCACHE}
0065 }
0066 };
0067
0068 static void initPLL(void);
0069 static void initEBIU(void);
0070 static void initGPIO(void);
0071
0072 RTEMS_SYSINIT_ITEM(
0073 bfin_interrupt_init,
0074 RTEMS_SYSINIT_BSP_PRE_DRIVERS,
0075 RTEMS_SYSINIT_ORDER_MIDDLE
0076 );
0077
0078 void bsp_start(void)
0079 {
0080
0081
0082 *(uint32_t volatile *) DMEM_CONTROL |= DMEM_CONTROL_PORT_PREF0;
0083 *(uint32_t volatile *) DMEM_CONTROL &= ~DMEM_CONTROL_PORT_PREF1;
0084 bfin_mmu_init(&mmuRegions);
0085 rtems_cache_enable_instruction();
0086 rtems_cache_enable_data();
0087
0088 Init_RTC();
0089
0090 initPLL();
0091 initEBIU();
0092 initGPIO();
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102 static void initPLL(void) {
0103
0104 #ifdef BISON
0105 unsigned int n;
0106
0107
0108 *((uint16_t*)PLL_LOCKCNT) = 0x1000;
0109 *((uint16_t*)PLL_DIV) = PLL_CSEL|PLL_SSEL;
0110 *((uint16_t*)PLL_CTL) = PLL_MSEL|PLL_DF;
0111
0112
0113 __asm__ ("cli r0;");
0114 __asm__ ("idle;");
0115 __asm__ ("sti r0;");
0116
0117
0118 for (n=0; n<200; n++) {}
0119 #endif
0120
0121 }
0122
0123
0124
0125
0126
0127
0128
0129 static void initEBIU(void) {
0130
0131
0132
0133
0134
0135
0136
0137
0138 *(uint16_t volatile *) EBIU_AMGCTL |= EBIU_AMGCTL_CDPRIO;
0139
0140 #ifdef BISON
0141
0142 *((uint32_t*)EBIU_AMBCTL0) = 0x7bb07bb0L;
0143 *((uint32_t*)EBIU_AMBCTL1) = 0x7bb07bb0L;
0144 *((uint16_t*)EBIU_AMGCTL) = 0x000f;
0145
0146
0147
0148
0149
0150
0151 #endif
0152 }
0153
0154
0155
0156
0157
0158
0159 static void initGPIO(void) {
0160 #if (!BFIN_ON_SKYEYE)
0161 *(uint16_t volatile *) PORT_MUX = 0;
0162
0163
0164
0165
0166 *(uint16_t volatile *) PORTF_FER = 0x0003;
0167 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
0168 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x003c;
0169 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
0170 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
0171 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
0172 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
0173 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
0174 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0fc0;
0175
0176 *(uint16_t volatile *) PORTG_FER = 0x0000;
0177 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
0178 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
0179 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
0180 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
0181 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
0182 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
0183 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
0184 *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
0185
0186
0187 *(uint16_t volatile *) PORTH_FER = 0xffff;
0188 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
0189 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
0190 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
0191 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
0192 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
0193 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
0194 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
0195 *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
0196 #endif
0197 }
0198
0199
0200
0201
0202
0203 void setLEDs(uint8_t value) {
0204
0205 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_CLEAR_OFFSET) =
0206 (uint16_t) (~value & 0x3f) << 6;
0207 *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_SET_OFFSET) =
0208 (uint16_t) (value & 0x3f) << 6;
0209 }
0210
0211
0212
0213
0214 uint8_t getLEDs(void) {
0215 uint16_t r;
0216
0217 r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
0218 return (uint8_t) ((r >> 6) & 0x3f);
0219 }
0220
0221 uint8_t getButtons(void) {
0222 uint16_t r;
0223
0224 r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
0225
0226 return (uint8_t) ((r >> 2) & 0x0f);
0227 }
0228
0229