You are on page 1of 14

Code

SWITCH

EQU 0x40024004 ;PE0

LED

EQU 0x40024008 ;PE1

SYSCTL_RCGCGPIO_R

EQU 0x400FE608

SYSCTL_RCGC2_GPIOE

EQU 0x00000010 ; port E Clock Gating Control

SYSCTL_RCGC2_GPIOF

EQU 0x00000020 ; port F Clock Gating Control

GPIO_PORTE_DATA_R

EQU 0x400243FC

GPIO_PORTE_DIR_R

EQU 0x40024400

GPIO_PORTE_AFSEL_R

EQU 0x40024420

GPIO_PORTE_PUR_R

EQU 0x40024510

GPIO_PORTE_DEN_R

EQU 0x4002451C

NVIC_ST_CURRENT_R

EQU 0xE000E018

GPIO_PORTF_DATA_R

EQU 0x400253FC

GPIO_PORTF_DIR_R

EQU 0x40025400

GPIO_PORTF_AFSEL_R

EQU 0x40025420

GPIO_PORTF_DEN_R

EQU 0x4002551C

DELAYVALUE

EQU 1290000

NVIC_ST_RELOAD_R

EQU 0xE000E014

NVIC_ST_CTRL_R

EQU 0xE000E010

SYSCTL_RCGC2_R

EQU 0x400FE108

AREA DATA, ALIGN=2


SIZE

EQU 50
;You MUST use these two buffers and two variables
;You MUST not change their names

DataBuffer SPACE SIZE*4


TimeBuffer SPACE SIZE*4

DataPt

SPACE 4

TimePt

SPACE 4
;These names MUST be exported

EXPORT DataBuffer
EXPORT TimeBuffer
EXPORT DataPt
EXPORT TimePt

ALIGN
AREA |.text|, CODE, READONLY, ALIGN=2
THUMB
EXPORT Start
IMPORT TExaS_Init
CPSIE I

Start BL TExaS_Init

; TExaS voltmeter, scope runs on interrupts

; running at 80 MHz, scope voltmeter on PD3

LDR R0, = SYSCTL_RCGC2_R


LDR R1, [R0]
ORR R1, R1, #0x30
STR R1, [R0]

NOP
NOP
;-----------------------------------------------------------------------------PORTE Initialization
LDR R0, = GPIO_PORTE_DIR_R
ORR R1, R1, #0x02
BIC R1, R1, #0x01
STR R1, [R0]

;Set PE1 as output and PE0 as input

LDR R1, =GPIO_PORTE_AFSEL_R


LDR R0, [R1]

; previous value

BIC R0, R0, #0x03

; disable alt funct

STR R0, [R1]

LDR R0, =GPIO_PORTE_DEN_R


ORR R1, R1, #0x03
STR R1, [R0]
;-------------------------------------------------------------------------- PORTF INITIALIZATION
LDR R0, = GPIO_PORTF_DIR_R
ORR R1, R1, #0x04
STR R1, [R0]

;Set PE1 as output and PE0 as input

LDR R1, =GPIO_PORTF_AFSEL_R


LDR R0, [R1]

; previous value

BIC R0, R0, #0x04

; disable alt funct

STR R0, [R1]

LDR R0, =GPIO_PORTF_DEN_R


ORR R1, R1, #0x04
STR R1, [R0]

;Turn on led
LDR R0,=GPIO_PORTE_DATA_R
LDR R1,[R0]
ORR R1,#0x02
STR R1,[R0]
;----------------------------------------------------------------------------

; bit 1 is output and with a 1 is lit

; initialize debugging dump


BL Debug_Init
loop BL

Debug_Capture

LDR R0, =GPIO_PORTF_DATA_R


LDR R1, [R0]
EOR R1, #0x04
STR R1, [R0]
;-------------------------------------------------------------------------LDR R0, = DELAYVALUE
Delay SUBS R0, R0, #1
BNE Delay

;----------------------------------------------------------------------------

LDR R2, =GPIO_PORTE_DATA_R


LDR R1, [R2]
AND R1, R1, #0x01
AND R0, R0, #0x00
CMP R0, R1

; checks if PE1 contains a 1, i.e. switch is not

BEQ not_pressed

; go to not pressed subroutine

ORR R0, R0, #0x01


CMP R0, R1
BEQ pressed

; checks if PE1 contains a 0, i.e. switch is pressed


;if the switch is pressed then go to the pressed subroutine

pressed

LDR R0, =GPIO_PORTE_DATA_R


LDR R1, [R0]

; put the contents of data into R1

EOR R2, R1, #0x02

;switch the bit from 1 to 0, or 0 to 1

STR R2, [R0]

; store switched bit into data register

B done

; toggle light

not_pressed

LDR R0, =GPIO_PORTE_DATA_R


LDR R1, [R0]
ORR R1, R1, #0x02

; make sure that light is turned on

STR R1, [R0]

; store in R0

done
B loop

;------------Debug_Init-----------; Initializes the debugging instrument


; Input: none
; Output: none
; Modifies: none
; Note: push/pop an even number of registers so C compiler is happy
Debug_Init

LDR R1, =NVIC_ST_CTRL_R


MOV R0, #0

; Clear Enable

STR R0, [R1]


; set reload to maximum reload value
LDR R1, =NVIC_ST_RELOAD_R
LDR R0, =0x00FFFFFF

; Specify RELOAD value

STR R0, [R1]

; reload at maximum

; writing any value to CURRENT clears it


LDR R1, =NVIC_ST_CURRENT_R
MOV R0, #0
STR R0, [R1]

; clear counter
; enable SysTick with core clock

LDR R1, =NVIC_ST_CTRL_R


MOV R0, #0x0005

; Enable but no interrupts (later)

STR R0, [R1]

; ENABLE and CLK_SRC bits set

LDR R12, = 0xFFFFFFFF


MOV R2,#50

LDR R1, = DataBuffer


LDR R3, = TimeBuffer
LDR R0, = DataPt
STR R1, [R0]
LDR R2, = TimePt
STR R3, [R2]
MOV R2, #50
Repeat

; disable SysTick during setup


STR R12, [R1],#4
STR R12, [R3],#4
SUBS R2,#1
BNE Repeat

BX LR

;------------Debug_Capture------------

; Dump Port E and time into buffers


; Input: none
; Output: none
; Modifies: none
; Note: push/pop an even number of registers so C compiler is happy
Debug_Capture
;execution time = total cycles in subroutine * 12.5ns
;

29 instructions, so 58 cycles total in subroutine * 12.5ns = 725 ns

;time between calls = delay + cycles *12.5


;

24 cycles between calls * 12.5 = 300 ns + 62ms delay = 62000300 ns

;Percentage overhead = 100* execution time/time between calls


;

OHD = 100* 725/62000300 = .00116935%

PUSH {R0-R6,R12}; store registers

;check to see if the databuffer is full


LDR R0,=DataBuffer
ADD R0,#200
LDR R1,=DataPt;
LDR R6,[R1]
CMP

R6,R0;

BHS Done
; if the DataPt>= DataBuffer last spot then return
;read port e and the SysTick timer
LDR

R2,=GPIO_PORTE_DATA_R

LDR R3,[R2];

LDR R4,=NVIC_ST_CURRENT_R
LDR R5,[R4];

AND R3,#0x03
AND R12,R3,#0x01
LSL R12,#4
ORR R3,R12

; put value of bit 0 into bit 4

AND R12,R3, #0x02


LSR R12,#1;
AND R3,#0x10; clear all bits except bit 4
ORR R3,R12;put value of bit 1 into bit 0

STR R3,[R6]; R1=DataPt

;Increment dataPt
ADD R6,#4;
STR R6,[R1]

;Dump time into TimeBuffer


LDR R0,=TimePt;
LDR R1,[R0];
STR R5,[R1]
; Store the time from current into buffer

; isolate bit 0 and 1

;Increment TimePt
ADD R1,#4
STR R1,[R0]

Done

POP

{R0-R6, R12}
BX

ALIGN
END

; restore registers

LR

; make sure the end of this section is aligned


; end of file

Calculations of Debug Capture Run Time

Execution time = total cycles in subroutine * 12.5ns


29 instructions, so 58 cycles total in subroutine * 12.5ns = 725 ns

Time between calls = delay + cycles *12.5


24 cycles between calls * 12.5 = 300 ns + 62ms delay = 62000300 ns = .062 s

Percentage overhead = 100* execution time/time between calls


OHD = 100* 725/62000300 = .00116935%

Data.txt
:020000042000DA
:0350C00A4080000CC08000000000000
:0000000000000000000000000000000
:0000000000000000100000000000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:1000000100000001100000010000000
:10000001000000042FEFF00A241B100
:285620062C81300C20BC500224F7600
:2922700E2D5D80042198A00A25C3B00
:2A0EC0062E39D00C2264F00226A0000
:2ADB100E2F0620042341400A277C500
:2BB760062FE2700C241D90022858A00
:2C83B00E20BED00424F9E00A2924F00
:2D600006219B200C25C630022A01400
:2E3C500E2267700426A2800A2ADD900
:2F18A0062343C00C277ED0022BB9E00
:0101900082EC
:00000001FF

Calculation for LED Period:

0x0062850E 0x0013C874 = 0x4ebc9a = 5160090

5160090 * 12 ns = 0.064501125 = 64.501125 ms

You might also like