tabticker.fth (3045B)
1 \ SysTickDisco072.fth - Cortex-M0 ticker for STM32F072B-DISCO board 2 3 (( 4 Copyright (c) 2010, 2011, 2014 5 MicroProcessor Engineering 6 133 Hill Lane 7 Southampton SO15 5AF 8 England 9 10 tel: +44 (0)23 8063 1441 11 fax: +44 (0)23 8033 9691 12 email: mpe@mpeforth.com 13 tech-support@mpeforth.com 14 web: http://www.mpeforth.com 15 Skype: mpe_sfp 16 17 From North America, our telephone and fax numbers are: 18 011 44 23 8063 1441 19 011 44 23 8033 9691 20 901 313 4312 (North American access number to UK office) 21 22 23 To do 24 ===== 25 26 Change history 27 ============== 28 20140207 SFP003 Converted for STM32F072B-DISCO board. 29 20110218 MPE002 Added timebase extensions. 30 )) 31 32 only forth definitions 33 decimal 34 35 \ =========== 36 \ *> drivers 37 \ =========== 38 \ *S System Ticker 39 \ **************** 40 \ *P The source code discussed in this section may be found in 41 \ ** the file *\i{Drivers/SysTickDisco072.fth}. 42 43 \ *P The system ticker uses the Cortex-M0 *\i{SysTick} timer. 44 \ ** Although the *\i{SysTick} timer is common to all Cortex-M0 45 \ ** devices, there is no guarantee that they have the same 46 \ ** clocking arrangements. Consequently there are different 47 \ ** drivers for different implementations. 48 49 \ *P The STM32 implementation is fed with the system clock and 50 \ ** has an option to divide it by 8, controlled by bit 2 of the 51 \ ** SysTick Control and Status Register (ARM DDI 0337, Rev E, 52 \ ** page 8-8). 53 \ *( 54 \ *B Bit2=0: SysTick clock is HCLK/8. 55 \ *B Bit2=1: SysTick clock is HCLK. 56 \ *) 57 \ *P This code always uses HCLK/8. 58 59 60 variable <ticks> 61 62 : ticks \ -- ms 63 \ *G Returns a 32 bit number of milliseconds that eventually 64 \ ** wraps. 65 <ticks> @ 66 ; 67 compiler 68 : ticks \ -- ms 69 <ticks> @ 70 ; 71 target 72 73 : SysTicker \ -- 74 \ *G Ticker ISR action. 75 tick-ms <ticks> +! \ update ticker 76 ; 77 ' SysTicker SysTickvec# EXC: SysTickISR \ -- addr 78 \ *G Setting the high level ISR. 79 80 tick-ms system-speed 8 / #1000 */ 1- equ /SysTick \ -- x 81 \ +G Initial value of the SysTick Reload register. 82 83 : start-clock \ -- 84 \ *G Initialise the system ticker to run with a period of 85 \ ** *\fo{tick-ms} milliseconds. 86 _SCS 87 /SysTick over stRVR + ! \ set ticker rate 88 $0003 over stCSR + ! \ enable, bit 0 = enable, bit 1=interrupt 89 \ bit 2 = clock source (1=sysclk, 0=sysclk/8) 90 $FF over $0D23 + c! \ set SysTick priority to lowest 91 drop 92 ei 93 ; 94 95 : stop-clock \ -- 96 \ *G Stop the sytem ticker. 97 bit0 _SCS stCSR + bic! ; 98 99 : later \ n -- n' 100 \ *G Generates the timebase value for termination in 101 \ ** n millseconds time. 102 ticks + 103 ; 104 105 : timedout? \ n -- flag ; true if timed out 106 \ *G Flag is returned true if the timebase value n has timed out. 107 \ ** *\fo{TIMEDOUT?} does not call *\fo{PAUSE}. 108 ticks - 0< \ must use circular arithmetic 109 ; 110 111 compiler 112 : later \ n -- n' 113 ticks + 114 ; 115 116 : timedout? \ n -- flag ; true if timed out 117 ticks - 0< \ must use circular arithmetic 118 ; 119 target 120 121 : ms \ n -- 122 \ *G Waits for n milliseconds. 123 later begin 124 pause dup timedout? 125 until 126 drop 127 ; 128 129 130 \ ====== 131 \ *> ### 132 \ ====== 133 134 decimal 135