Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * startup.c
- *
- */
- void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
- #ifdef SIMULATOR
- #define DELAY_COUNT 100
- #else
- #define DELAY_COUNT 1000000
- #endif
- #define GPIO_D_MODER (volatile unsigned int *) 0X40020C00
- #define GPIO_D_ODR_LOW (volatile unsigned int *) (0X40020C00 + 0x14)
- #define SCB_VTOR (volatile unsigned int *) 0xE000ED08
- #define STK_LOAD (volatile unsigned int *) (0xE000E014)
- #define STK_CTRL (volatile unsigned int *) (0xE000E010)
- #define STK_VAL (volatile unsigned int *) (0xE000E018)
- static volatile int systick_flag;
- static volatile int delay_count;
- void startup ( void )
- {
- __asm volatile(
- " LDR R0,=0x2001C000\n" /* set stack */
- " MOV SP,R0\n"
- " BL main\n" /* call main */
- "_exit: B .\n" /* never return */
- ) ;
- }
- void handler_X ( void )
- {
- *GPIO_D_ODR_LOW = ~*GPIO_D_ODR_LOW;
- }
- void init_handler_X(void)
- {
- * ( (void (**) (void) ) 0x2001C03C) = handler_X;
- systick_flag = 0;
- }
- void init_app (void)
- {
- /* Initiera port D och undantagsvektor */
- *GPIO_D_MODER = 0x00005555;
- *SCB_VTOR = 0x2001C000;
- delay_count = DELAY_COUNT;
- init_handler_X();
- }
- void delay_1mikro(void)
- {
- systick_flag = 0;
- *STK_CTRL = 0;
- *STK_LOAD = ( 168- 1);
- *STK_VAL = 0;
- *STK_CTRL = 7;
- }
- void delay (unsigned int count)
- {
- if ( count == 0 )
- {
- return;
- }
- delay_count = count;
- systick_flag = 0;
- delay_1mikro();
- }
- void systick_irq_handler (void)
- {
- *STK_CTRL = 0;
- delay_count--;
- if (delay_count > 0)
- {
- delay_1mikro();
- }
- else
- {
- systick_flag = 1;
- }
- }
- void main(void)
- {
- init_app();
- *GPIO_D_ODR_LOW = 0;
- delay (DELAY_COUNT);
- *GPIO_D_ODR_LOW = 0xFF;
- while (1)
- {
- if (systick_flag)
- break;
- }
- *GPIO_D_ODR_LOW = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement