Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #ifdef SIMULATOR
  2. #define DELAY_COUNT 100
  3. #else
  4. #define DELAY_COUNT 1000000
  5. #endif
  6.  
  7. volatile int systick_flag;
  8. volatile int delay_count;
  9.  
  10. #define GPIO_D 0x40020C00
  11. #define GPIO_MODER ((volatile unsigned int *) (GPIO_D))
  12. #define GPIO_OTYPER ((volatile unsigned short *) (GPIO_D+0x4))
  13. #define GPIO_PUPDR ((volatile unsigned int *) (GPIO_D+0xC))
  14. #define GPIO_IDR_LOW ((volatile unsigned char *) (GPIO_D+0x10))
  15. #define GPIO_IDR_HIGH ((volatile unsigned char *) (GPIO_D+0x11))
  16. #define GPIO_ODR_LOW ((volatile unsigned char *) (GPIO_D+0x14))
  17. #define GPIO_ODR_HIGH ((volatile unsigned char *) (GPIO_D+0x15))
  18.  
  19.  
  20. #define STK_CTRL ((volatile unsigned int *)(0xE000E010))
  21. #define STK_LOAD ((volatile unsigned int *)(0xE000E014))
  22. #define STK_VAL ((volatile unsigned int *)(0xE000E018))
  23.  
  24. //_______________________________________________________________________________________________________________________________________________________________
  25. void init_app(void){
  26. *GIPO_MODER = 0x55555555;
  27.  
  28. }
  29.  
  30. void delay_1mikro( void )
  31. {
  32. *STK_CTRL = 0;
  33. *STK_LOAD = ( 168 -1 );
  34. *STK_VAL = 0;
  35. *STK_CTRL = 7;
  36. }
  37.  
  38. void delay( unsigned int count )
  39. {
  40. if( count == 0)
  41. return;
  42. delay_count = count;
  43. systick_flag = 0;
  44. delay_1mikro();
  45. }
  46.  
  47. void systick_irq_handler( void )
  48. {
  49. *STK_CTRL = 0;
  50. delay_count -- ;
  51. if( delay_count > 0 )
  52. delay_1mikro();
  53. else
  54. systick_flag = 1;
  55. }
  56.  
  57. //_______________________________________________________________________________________________________________________________________________________________
  58. void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
  59.  
  60. void startup ( void )
  61. {
  62. __asm volatile(
  63. " LDR R0,=0x2001C000\n" /* set stack */
  64. " MOV SP,R0\n"
  65. " BL main\n" /* call main */
  66. "_exit: B .\n" /* never return */
  67. ) ;
  68. }
  69. //_______________________________________________________________________________________________________________________________________________________________
  70.  
  71. void main(void)
  72. {
  73. init_app();
  74. *GIPO_ODR_LOW = 0;
  75. delay(DELAY_COUNT);
  76. *GIPO_ODR_LOW = 0xFF;
  77. while(1){
  78. if(systick_flag){
  79. break;
  80. //kod som kan utföras under väntetiden
  81. }
  82. //Kod som "väntar" på time-out
  83. *GPIO_ODR_LOW = 0;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement