Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 5.44 KB | None | 0 0
  1. ; Definitions  -- references to 'UM' are to the User Manual.
  2.  
  3. ; Timer Stuff -- UM, Table 173
  4.  
  5. T0  equ 0xE0004000      ; Timer 0 Base Address
  6. T1  equ 0xE0008000
  7.  
  8. IR  equ 0           ; Add this to a timer's base address to get actual register address
  9. TCR equ 4
  10. MCR equ 0x14
  11. MR0 equ 0x18
  12.  
  13. TimerCommandReset   equ 2
  14. TimerCommandRun equ 1
  15. TimerModeResetAndInterrupt  equ 3
  16. TimerResetTimer0Interrupt   equ 1
  17. TimerResetAllInterrupts equ 0xFF
  18.  
  19. ; VIC Stuff -- UM, Table 41
  20. VIC equ 0xFFFFF000      ; VIC Base Address
  21. IntEnable   equ 0x10
  22. VectAddr    equ 0x30
  23. VectAddr0   equ 0x100
  24. VectCtrl0   equ 0x200
  25.  
  26. Timer0ChannelNumber equ 4   ; UM, Table 63
  27. Timer0Mask  equ 1<<Timer0ChannelNumber  ; UM, Table 63
  28. IRQslot_en  equ 5       ; UM, Table 58
  29.  
  30. IO1DIR  EQU 0xE0028018
  31. IO1SET  EQU 0xE0028014
  32. IO1CLR  EQU 0xE002801C
  33. IO1PIN  EQU 0xE0028010
  34. IO0DIR EQU 0xE0028008
  35. IO0SET EQU 0xE0028004
  36. IO0CLR EQU 0xE002800C
  37.  
  38.     AREA    InitialisationAndMain, CODE, READONLY
  39.     IMPORT  main
  40.  
  41. ; (c) Mike Brady, 2014–2016.
  42.  
  43.     EXPORT  start
  44. start
  45. ; |----------------------------|
  46. ; |----INITIALISTION CODE------|
  47. ; |----------------------------|
  48.  
  49. ; Initialise the VIC
  50.     ldr r0,=VIC         ; looking at you, VIC!
  51.     ldr r1,=irqhan
  52.     str r1,[r0,#VectAddr0]  ; associate our interrupt handler with Vectored Interrupt 0
  53.     mov r1,#Timer0ChannelNumber+(1<<IRQslot_en)
  54.     str r1,[r0,#VectCtrl0]  ; make Timer 0 interrupts the source of Vectored Interrupt 0
  55.     mov r1,#Timer0Mask
  56.     str r1,[r0,#IntEnable]  ; enable Timer 0 interrupts to be recognised by the VIC
  57.     mov r1,#0
  58.     str r1,[r0,#VectAddr]       ; remove any pending interrupt (may not be needed)
  59. ; Initialise Timer 0
  60.     ldr r0,=T0          ; looking at you, Timer 0!
  61.     mov r1,#TimerCommandReset
  62.     str r1,[r0,#TCR]
  63.     mov r1,#TimerResetAllInterrupts
  64.     str r1,[r0,#IR]
  65.     ldr r1,=(14745600/2)-1   ; 5 ms = 1/200 second
  66.     str r1,[r0,#MR0]
  67.     mov r1,#TimerModeResetAndInterrupt
  68.     str r1,[r0,#MCR]
  69.     mov r1,#TimerCommandRun
  70.     str r1,[r0,#TCR]
  71. ;from here, initialisation is finished, so it should be the main body of the main program
  72.    
  73. ; |----------------------------|
  74. ; |---INITIALISE SCHEDULER-----|
  75. ; |----------------------------|
  76.  
  77.  
  78.     LDR lr,=programTwo 
  79.     LDR sp,=stackTwo
  80.     STMFD sp!, {r0-r12, lr}
  81.     LDR R1,=stackPointTwo
  82.     STR sp, [R1]
  83.    
  84.     LDR R0,=programRunning
  85.     MOV R1, #1
  86.     STR R1, [R0]
  87.    
  88.     LDR sp,=stackOne
  89.    
  90.     B programOne
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. ; |----------------------------|
  119. ; |---------THREAD ONE---------|
  120. ; |----------------------------|
  121.  
  122.  
  123. programOne
  124.  
  125.     ldr r1,=IO1DIR
  126.     ldr r2,=0x000f0000  ;select P1.19--P1.16
  127.     str r2,[r1]     ;make them outputs
  128.     ldr r1,=IO1SET
  129.     str r2,[r1]     ;set them to turn the LEDs off
  130.     ldr r2,=IO1CLR
  131. ; r1 points to the SET register
  132. ; r2 points to the CLEAR register
  133.  
  134.     ldr r5,=0x00100000  ; end when the mask reaches this value
  135. wloop   ldr r3,=0x00010000  ; start with P1.16.
  136. floop   str r3,[r2]     ; clear the bit -> turn on the LED
  137.  
  138. ;delay for about a half second
  139.     ldr r4,=2000000
  140. dloop   subs    r4,r4,#1
  141.     bne dloop
  142.  
  143.     str r3,[r1]     ;set the bit -> turn off the LED
  144.     mov r3,r3,lsl #1    ;shift up to next bit. P1.16 -> P1.17 etc.
  145.     cmp r3,r5
  146.     bne floop
  147.     b   wloop
  148.  
  149.  
  150. endProgramOne b endProgramOne
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. ; |----------------------------|
  180. ; |---------THREAD TWO---------|
  181. ; |----------------------------|
  182.  
  183.  
  184. programTwo
  185.  
  186.     ldr r1,=IO1DIR
  187.     ldr r2,=0x000f0000  ;select P1.19--P1.16
  188.     str r2,[r1]     ;make them outputs
  189.     ldr r1,=IO1SET
  190.     str r2,[r1]     ;set them to turn the LEDs off
  191.     ldr r2,=IO1CLR
  192. ; r1 points to the SET register
  193. ; r2 points to the CLEAR register
  194.  
  195.     ldr r5,=0x00100000  ; end when the mask reaches this value
  196. wloop2  ldr r3,=0x00010000  ; start with P1.16.
  197. floop2  str r3,[r2]     ; clear the bit -> turn on the LED
  198.  
  199. ;delay for about a half second
  200.     ldr r4,=200000
  201. dloop2  subs    r4,r4,#1
  202.     bne dloop2
  203.  
  204.     str r3,[r1]     ;set the bit -> turn off the LED
  205.     mov r3,r3,lsl #1    ;shift up to next bit. P1.16 -> P1.17 etc.
  206.     cmp r3,r5
  207.     bne floop2
  208.     b   wloop2
  209.  
  210.  
  211.  
  212. endProgramTwo b endProgramTwo
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248. ; |----------------------------|
  249. ; |---------INTERRUPTS---------|
  250. ; |----------------------------|
  251.     AREA    InterruptStuff, CODE, READONLY
  252. irqhan  sub lr,lr,#4
  253.     stmfd   sp!,{r0-r12, lr}    ; the lr will be restored to the pc
  254.  
  255.     LDR R0,=programRunning
  256.     LDR R1, [R0]
  257.     CMP R1, #1
  258.    
  259.     LDRNE R2,=stackPointTwo
  260.     LDREQ R2,=stackPointOne
  261.     STR sp, [R2]
  262.    
  263.     LDRNE R2,=stackPointOne
  264.     LDREQ R2,=stackPointTwo
  265.     LDR sp, [R2]
  266.    
  267.     EOR R1, #0x3
  268.     STR R1, [R0]
  269.  
  270. ;here you'd put the unique part of your interrupt handler
  271. ;all the other stuff is "housekeeping" to save registers and acknowledge interrupts
  272. ;this is where we stop the timer from making the interrupt request to the VIC
  273. ;i.e. we 'acknowledge' the interrupt
  274.     ldr r0,=T0
  275.     mov r1,#TimerResetTimer0Interrupt
  276.     str r1,[r0,#IR]     ; remove MR0 interrupt request from timer
  277. ;here we stop the VIC from making the interrupt request to the CPU:
  278.     ldr r0,=VIC
  279.     mov r1,#0
  280.     str r1,[r0,#VectAddr]   ; reset VIC
  281.  
  282.     ldmfd   sp!,{r0-r12, pc}^   ; return from interrupt, restoring pc from lr
  283.                 ; and also restoring the CPSR
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. ; |----------------------------|
  299. ; |---------SUBROUTINE---------|
  300. ; |----------------------------|
  301.     AREA    Subroutines, CODE, READONLY
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.     AREA    Stuff, DATA, READWRITE
  337. programRunning DCD 0
  338. stackOne SPACE 1024
  339. stackTwo SPACE 1024
  340. stackPointOne DCD 0
  341. stackPointTwo DCD 0
  342.    
  343. fireWorks DCD 0x1, 0x2, 0x4, 0x8
  344.  
  345.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement