.global _main
/* main program */
_main:

/* user code here */
      bl DEBUG_INIT
     
      adr r0,Testni
      bl SNDS_DEBUG

      adr r0,Received
      mov r1,#10
      bl RCVS_DEBUG

     
LOOP: bl RCV_DEBUG
      bl SND_DEBUG
      b LOOP

/* end user code */

_wait_for_ever:
  b _wait_for_ever

DEBUG_INIT:
      stmfd r13!, {r0, r1, r14}
      ldr r0, =DBGU_BASE
@      mov r1, #26        @  BR=115200
      mov r1, #156        @  BR=19200
      str r1, [r0, #DBGU_BRGR]
      mov r1, #(1 << 11)
      str r1, [r0, #DBGU_MR]
      mov r1, #0b1010000
      str r1, [r0, #DBGU_CR]
      ldmfd r13!, {r0, r1, pc}

RCV_DEBUG:
      stmfd r13!, {r1, r14}
      ldr r1, =DBGU_BASE
RCVD_LP:
      ldr r0, [r1, #DBGU_SR]
      tst r0, #1
      beq RCVD_LP
      ldr r0, [r1, #DBGU_RHR]
      ldmfd r13!, {r1, pc}

SND_DEBUG:
      stmfd r13!, {r1, r2, r14}
      ldr r1, =DBGU_BASE
SNDD_LP:
      ldr r2, [r1, #DBGU_SR]
      tst r2, #(1 << 1)
      beq SNDD_LP
      str r0, [r1, #DBGU_THR]
      ldmfd r13!, {r1, r2, pc}

RCVS_DEBUG:
      stmfd r13!, {r1, r2, r14}
      mov r2, r0
RCVSD_LP:
      bl RCV_DEBUG
      strb r0, [r2], #1
      subs r1, r1, #1
      bne RCVSD_LP
      mov r0, #0
      strb r0, [r2]
      ldmfd r13!, {r1, r2, pc}

SNDS_DEBUG:
      stmfd r13!, {r2, r14}
      mov r2, r0
SNDSD_LP:
      ldrb r0, [r2], #1
      cmp r0, #0
      beq SNDD_END
      bl SND_DEBUG
      b SNDSD_LP
SNDD_END:
      ldmfd r13!, {r2, pc} 


/* constants */
Testni:  .asciz "DBGU Test [First type 10 characters and then one by one - echo]:\n"
Received: .asciz "                                                                      "

          .align

_Lstack_end:
  .long __STACK_END__

.end
Zadnja sprememba: torek, 14. december 2021, 18.32