// Podane so samo dodane spremenljivke, glavni program in podprogrami

// Start of data section
  .data
LEDSTAT: .word  0  // LED state
MSECCNT: .word  0  //MSecs counter for SysTick_Handler
MSECMAX: .word  500 //MSecs interval for SysTick_Handler

// Start of text section
  .text

  .type  main, %function
  .global main

    .align
main:

    bl INIT_IO    // Priprava za kontrolo LED diode
    bl INIT_TC_PSP // Priprava SysTick časovnika s prekinitvami

endloop: b endloop


INIT_TC_PSP:
  push {r0, r1, lr}
ldr r1, =SCS_BASE

ldr r0, =SYSTICK_RELOAD_1MS
str r0, [r1, #SCS_SYST_RVR]

ldr r0, =0
str r0, [r1, #SCS_SYST_CVR]

ldr r0, =7      // TickINT Bit also set to 1
str r0, [r1, #SCS_SYST_CSR]

  pop {r0, r1, pc}


/**
* @brief  This is the code that gets called when SysTick timer triggers interrupt
* @param  None
* @retval None
*/

.global SysTick_Handler

.section  .text.SysTick_Handler,"ax",%progbits
.type  SysTick_Handler, %function


SysTick_Handler:
    push {r3, r4, r5, lr}

ldr r3,=MSECCNT  // Load MSecs Counter value
ldr r4,[r3]
add r4,r4,#1 // Increment (+1)
str r4,[r3]

ldr r3,=MSECMAX  // Load MAX value
ldr r5,[r3]

    cmp r4,r5        // End of interval ?
    blo RET

// End of interval - reset counter and toggle LED
    mov r4,#0    // reset MSecs Counter
ldr r3,=MSECCNT
str r4,[r3]

ldr r3,=LEDSTAT // Check LED STATE
ldr r4,[r3]
    cmp r4,#0    // is it OFF ?
beq LON

mov r4,#0      // Set state and LED Off
str r4,[r3]

// Set GPIOx Pins to 1 (through BSSR register)
ldr    r3, =GPIOI_BASE      // Load GPIOI BASE addr.
mov    r4, #LEDs_OFF
str    r4, [r3,#GPIOx_BSSR] // Write to BSRR register

b RET

LON: // Set state and LED On
mov r4,#1
str r4,[r3]

// Set GPIOx Pins to 0 (through BSSR register)
ldr    r3, =GPIOI_BASE      // Load GPIOI BASE addr.
mov    r4, #LEDs_ON
str    r4, [r3,#GPIOx_BSSR] // Write to BSRR register


RET: pop {r3, r4, r5, pc}
Zadnja sprememba: sreda, 11. januar 2023, 13.27