Advertisement
Guest User

Untitled

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