Advertisement
Guest User

Untitled

a guest
May 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.47 KB | None | 0 0
  1. .syntax unified
  2. .global main, EXTI0_IRQHandler, EXTI1_IRQHandler
  3.  
  4. .include "macros.s"
  5.  
  6.  
  7.  
  8. main:
  9.   bl init_gpio
  10.   bl init_audio
  11. starter:
  12.   GPIOx_ODR_set E, 12
  13.   GPIOx_ODR_toggle E, 13
  14.   mov r8, #0                    @ this will be our counter to ensure we only send 32 bits
  15.   mov r6, #0                    @ we will use this for the received message
  16.   mov r5, #32                   @ this will be our counter to ensure we only receive 32 bits
  17. @  mov r10, #31                  @ counter to ensure we lsl correctly to get the msb every loop
  18.   ldr r11, =0b10100001101110000111111111111111 @ store 440hz msg into r10
  19.   bl sender
  20.   bl clear_control_andCounter
  21.  
  22.  
  23.  
  24. sender:
  25.   push {lr}
  26.   cmp r8, #32
  27.   it ne
  28.   blne sender_message
  29.   it eq
  30.   bleq starter
  31.   pop {lr}
  32.   bl sender
  33.   bx lr
  34.  
  35. sender_message:
  36.   push {lr}
  37.   mov r12, #0
  38.   mov r12, r11  @r10 would be the binary msg
  39.   lsr r12, #31
  40.   cmp r12, #0
  41.   it eq
  42.   bleq write_bit_off
  43.   it ne
  44.   blne write_bit_on
  45.   pop {lr}
  46.   bx lr
  47.  
  48.  
  49.  
  50. write_bit_off:
  51.   GPIOx_ODR_clear E, 14
  52.   GPIOx_ODR_toggle E, 13
  53.   add r8, #1
  54.   lsl r11, #1
  55.   bl sender
  56.  
  57. write_bit_on:
  58.   GPIOx_ODR_set E, 14
  59.   GPIOx_ODR_toggle E, 13
  60.   add r8, #1
  61.   lsl r11, #1
  62.   bl sender
  63.  
  64.  
  65. clear_control_andCounter:
  66.   push {lr}
  67.   GPIOx_ODR_clear E, 12
  68.   mov r8, #0
  69.   pop {lr}
  70.   bx lr
  71.  
  72.  
  73.  
  74. data_reader:
  75.   push {lr}
  76.   GPIOx_IDR_read E, 11
  77.   it eq
  78.   bleq data_0_handler
  79.   it ne
  80.   blne data_1_handler
  81.   pop {lr}
  82.   bx lr
  83.  
  84. data_0_handler:
  85.   push {lr}
  86.   sub r5, #1
  87.   lsl r6, #1
  88.   pop {lr}
  89.   bx lr
  90.  
  91.  
  92. data_1_handler:
  93.   push {lr}
  94.   sub r5, #1
  95.   mov r4, #1
  96.   lsl r6, #1
  97.   orr r6, r6, r4
  98.   pop {lr}
  99.   bx lr
  100.  
  101. @  ldr r0, =storage
  102. @  ldr r1, [r0]
  103. @  lsl r1, #1
  104. @  str r1, [r0]
  105.  
  106. loop:
  107.   nop
  108.   b loop
  109.   @ good luck!
  110.  
  111.  
  112. continue:
  113.   push {lr}
  114.   cmp r5, #0
  115.   it ne
  116.   blne data_reader
  117.   pop {lr}
  118.   bx lr
  119.  
  120.  
  121. .type EXTI0_IRQHandler, %function
  122. EXTI0_IRQHandler:
  123.   push {r0-r6,r8-r12,lr}
  124.   @ mark this interrupt as "cleared" (i.e. no longer pending)
  125.   EXTI_PR_clear_pending 0
  126.   GPIOx_IDR_read H, 0
  127.   it eq
  128.   moveq r7, #0
  129.   it ne
  130.   movne r7, #1
  131.   pop {r0-r6,r8-r12,lr}
  132.   bx lr
  133.  
  134.  
  135. .type EXTI1_IRQHandler, %function
  136. EXTI1_IRQHandler:
  137.   push {r0-r2,r4-r6,r8-r12,lr}
  138.   @ mark this interrupt as "cleared" (i.e. no longer pending)
  139.   EXTI_PR_set_pending 0
  140.   mov r3, #1
  141.   @ check if control is 0
  142.   cmp r7, #1
  143.   it eq  @ if not, continue to data_receiver
  144.   bleq continue
  145.   pop {r0-r2,r4-r6,r8-r12,lr}
  146.   EXTI_PR_clear_pending 0
  147.   bx lr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement