-
Notifications
You must be signed in to change notification settings - Fork 2
/
wait.c
38 lines (32 loc) · 1.52 KB
/
wait.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Wait functions
// Jason Losh
//-----------------------------------------------------------------------------
// Hardware Target
//-----------------------------------------------------------------------------
// Target uC: TM4C123GH6PM
// System Clock: 40 MHz
//-----------------------------------------------------------------------------
// Device includes, defines, and assembler directives
//-----------------------------------------------------------------------------
#include <stdint.h>
#include "tm4c123gh6pm.h"
#include "wait.h"
//-----------------------------------------------------------------------------
// Subroutines
//-----------------------------------------------------------------------------
// Approximate busy waiting (in units of microseconds), given a 40 MHz system clock
void waitMicrosecond(uint32_t us)
{
__asm("WMS_LOOP0: MOV R1, #6"); // 1
__asm("WMS_LOOP1: SUB R1, #1"); // 6
__asm(" CBZ R1, WMS_DONE1"); // 5+1*3
__asm(" NOP"); // 5
__asm(" NOP"); // 5
__asm(" B WMS_LOOP1"); // 5*2 (speculative, so P=1)
__asm("WMS_DONE1: SUB R0, #1"); // 1
__asm(" CBZ R0, WMS_DONE0"); // 1
__asm(" NOP"); // 1
__asm(" B WMS_LOOP0"); // 1*2 (speculative, so P=1)
__asm("WMS_DONE0:"); // ---
// 40 clocks/us + error
}