⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc_statemachine.ls

📁 STM8S105 BLDC源代码
💻 LS
📖 第 1 页 / 共 2 页
字号:
   1                     ; C Compiler for STM8 (COSMIC Software)
   2                     ; Parser V4.9.10 - 10 Feb 2011
   3                     ; Generator (Limited) V4.3.6 - 15 Feb 2011
   4                     ; Optimizer V4.3.5 - 15 Feb 2011
  19                     	bsct
  20  0000               L3_bState:
  21  0000 00            	dc.b	0
  22  0001               L5_FaultingState:
  23  0001 00            	dc.b	0
 108                     ; 67 void StateMachineExec(void)
 108                     ; 68 {
 110                     	switch	.text
 111  0000               _StateMachineExec:
 113  0000 88            	push	a
 114       00000001      OFST:	set	1
 117                     ; 70   switch (bState)
 119  0001 b600          	ld	a,L3_bState
 121                     ; 154     break;
 122  0003 2724          	jreq	L11
 123  0005 4a            	dec	a
 124  0006 2735          	jreq	L31
 125  0008 4a            	dec	a
 126  0009 2743          	jreq	L51
 127  000b 4a            	dec	a
 128  000c 2750          	jreq	L71
 129  000e 4a            	dec	a
 130  000f 2768          	jreq	L12
 131  0011 4a            	dec	a
 132  0012 2775          	jreq	L32
 133  0014 4a            	dec	a
 134  0015 2603cc0099    	jreq	L52
 135  001a 4a            	dec	a
 136  001b 2603cc00a9    	jreq	L72
 137  0020 4a            	dec	a
 138  0021 2603cc00b9    	jreq	L13
 139  0026 cc00cd        	jra	L57
 140  0029               L11:
 141                     ; 72   case SM_RESET:
 141                     ; 73     bRetVal = sm_reset();
 143  0029 cd00cf        	call	_sm_reset
 145  002c 6b01          	ld	(OFST+0,sp),a
 146                     ; 74     if (bRetVal == STATE_REMAIN)
 148  002e 27f6          	jreq	L57
 150                     ; 76     else if (bRetVal == NEXT_STATE)
 152  0030 4a            	dec	a
 153  0031 2703cc00c9    	jrne	L702
 154                     ; 77       bState = SM_IDLE;
 156  0036 35010000      	mov	L3_bState,#1
 158  003a cc00cd        	jra	L57
 159                     ; 79       bState = SM_FAULT;
 160  003d               L31:
 161                     ; 81   case SM_IDLE:
 161                     ; 82     bRetVal = sm_idle();
 163  003d cd011e        	call	_sm_idle
 165  0040 6b01          	ld	(OFST+0,sp),a
 166                     ; 83     if (bRetVal == STATE_REMAIN)
 168  0042 27f6          	jreq	L57
 170                     ; 85     else if (bRetVal == NEXT_STATE)
 172  0044 4a            	dec	a
 173  0045 26ec          	jrne	L702
 174                     ; 86       bState = SM_STARTINIT;
 176  0047 35020000      	mov	L3_bState,#2
 178  004b cc00cd        	jra	L57
 179                     ; 88       bState = SM_FAULT;
 180  004e               L51:
 181                     ; 90   case SM_STARTINIT:
 181                     ; 91     bRetVal = sm_startinit();
 183  004e cd0148        	call	_sm_startinit
 185  0051 6b01          	ld	(OFST+0,sp),a
 186                     ; 92     if (bRetVal == STATE_REMAIN)
 188  0053 2778          	jreq	L57
 190                     ; 94     else if (bRetVal == NEXT_STATE)
 192  0055 4a            	dec	a
 193  0056 2671          	jrne	L702
 194                     ; 95       bState = SM_START;
 196  0058 35030000      	mov	L3_bState,#3
 198  005c 206f          	jra	L57
 199                     ; 97       bState = SM_FAULT;
 200  005e               L71:
 201                     ; 99   case SM_START:
 201                     ; 100     bRetVal = sm_start();
 203  005e cd0190        	call	_sm_start
 205  0061 6b01          	ld	(OFST+0,sp),a
 206                     ; 101     if (bRetVal == STATE_REMAIN)
 208  0063 2768          	jreq	L57
 210                     ; 103     else if (bRetVal == NEXT_STATE)
 212  0065 a101          	cp	a,#1
 213  0067 2606          	jrne	L331
 214                     ; 104       bState = SM_RUN;
 216  0069 35040000      	mov	L3_bState,#4
 218  006d 205e          	jra	L57
 219  006f               L331:
 220                     ; 105     else if (bRetVal == OPTIONAL_JUMP)
 222  006f a102          	cp	a,#2
 223  0071 2656          	jrne	L702
 224                     ; 106       bState = SM_STOP;
 226  0073 35050000      	mov	L3_bState,#5
 228  0077 2054          	jra	L57
 229                     ; 108       bState = SM_FAULT;
 230  0079               L12:
 231                     ; 110   case SM_RUN:
 231                     ; 111     bRetVal = sm_run();
 233  0079 cd01d9        	call	_sm_run
 235  007c 6b01          	ld	(OFST+0,sp),a
 236                     ; 112     if (bRetVal == STATE_REMAIN)
 238  007e 274d          	jreq	L57
 240                     ; 114     else if (bRetVal == NEXT_STATE)
 242  0080 4a            	dec	a
 243  0081 2646          	jrne	L702
 244                     ; 115       bState = SM_STOP;
 246  0083 35050000      	mov	L3_bState,#5
 248  0087 2044          	jra	L57
 249                     ; 117       bState = SM_FAULT;
 250  0089               L32:
 251                     ; 119   case SM_STOP:
 251                     ; 120     bRetVal = sm_stop();
 253  0089 cd0221        	call	_sm_stop
 255  008c 6b01          	ld	(OFST+0,sp),a
 256                     ; 121     if (bRetVal == STATE_REMAIN)
 258  008e 273d          	jreq	L57
 260                     ; 123     else if (bRetVal == NEXT_STATE)
 262  0090 4a            	dec	a
 263  0091 2636          	jrne	L702
 264                     ; 124       bState = SM_WAIT;
 266  0093 35060000      	mov	L3_bState,#6
 268  0097 2034          	jra	L57
 269                     ; 126       bState = SM_FAULT;
 270  0099               L52:
 271                     ; 128   case SM_WAIT:
 271                     ; 129     bRetVal = sm_wait();
 273  0099 cd0254        	call	_sm_wait
 275  009c 6b01          	ld	(OFST+0,sp),a
 276                     ; 130     if (bRetVal == STATE_REMAIN)
 278  009e 272d          	jreq	L57
 280                     ; 132     else if (bRetVal == NEXT_STATE)
 282  00a0 4a            	dec	a
 283  00a1 2626          	jrne	L702
 284                     ; 133       bState = SM_IDLE;
 286  00a3 35010000      	mov	L3_bState,#1
 288  00a7 2024          	jra	L57
 289                     ; 135       bState = SM_FAULT;
 290  00a9               L72:
 291                     ; 137   case SM_FAULT:
 291                     ; 138     bRetVal = sm_fault();
 293  00a9 cd0287        	call	_sm_fault
 295  00ac 6b01          	ld	(OFST+0,sp),a
 296                     ; 139     if (bRetVal == STATE_REMAIN)
 298  00ae 271d          	jreq	L57
 300                     ; 141     else if (bRetVal == NEXT_STATE)
 302  00b0 4a            	dec	a
 303  00b1 2616          	jrne	L702
 304                     ; 142       bState = SM_FAULT_OVER;
 306  00b3 35080000      	mov	L3_bState,#8
 308  00b7 2014          	jra	L57
 309                     ; 144       bState = SM_FAULT;
 310  00b9               L13:
 311                     ; 146   case SM_FAULT_OVER:
 311                     ; 147     bRetVal = sm_faultover();
 313  00b9 cd02ae        	call	_sm_faultover
 315  00bc 6b01          	ld	(OFST+0,sp),a
 316                     ; 148     if (bRetVal == STATE_REMAIN)
 318  00be 270d          	jreq	L57
 320                     ; 150     else if (bRetVal == NEXT_STATE)
 322  00c0 4a            	dec	a
 323  00c1 2606          	jrne	L702
 324                     ; 151       bState = SM_IDLE;
 326  00c3 35010000      	mov	L3_bState,#1
 328  00c7 2004          	jra	L57
 329  00c9               L702:
 330                     ; 153       bState = SM_FAULT;
 340  00c9 35070000      	mov	L3_bState,#7
 341  00cd               L57:
 342                     ; 172 }
 345  00cd 84            	pop	a
 346  00ce 81            	ret	
 658                     ; 174 SM_RetVal_t sm_reset(void)
 658                     ; 175 {
 659                     	switch	.text
 660  00cf               _sm_reset:
 662  00cf 89            	pushw	x
 663       00000002      OFST:	set	2
 666                     ; 180   vtimer_init();
 668  00d0 cd0000        	call	_vtimer_init
 670                     ; 182   vdev_init();
 672  00d3 cd0000        	call	_vdev_init
 674                     ; 183   pDevice = vdev_get();
 676  00d6 cd0000        	call	_vdev_get
 678  00d9 1f01          	ldw	(OFST-1,sp),x
 679                     ; 184   FaultingState = SM_NO_FAULT;
 681  00db 3f01          	clr	L5_FaultingState
 682                     ; 186   devInit(pDevice);
 684  00dd cd0000        	call	_devInit
 686                     ; 189 	g_pUserInterface = Get_UserInterface();
 688  00e0 cd0000        	call	_Get_UserInterface
 690  00e3 bf00          	ldw	L7_g_pUserInterface,x
 691                     ; 190     UserInterface_Init(pDevice,g_pUserInterface);
 693  00e5 89            	pushw	x
 694  00e6 1e03          	ldw	x,(OFST+1,sp)
 695  00e8 cd0000        	call	_UserInterface_Init
 697  00eb 85            	popw	x
 698                     ; 198 	keysInit(pDevice,g_pUserInterface);
 700  00ec be00          	ldw	x,L7_g_pUserInterface
 701  00ee 89            	pushw	x
 702  00ef 1e03          	ldw	x,(OFST+1,sp)
 703  00f1 cd0000        	call	_keysInit
 705  00f4 85            	popw	x
 706                     ; 200   driveInit(pDevice);
 708  00f5 1e01          	ldw	x,(OFST-1,sp)
 709  00f7 cd0000        	call	_driveInit
 711                     ; 202   vtimer_SetTimer(VTIM_KEY,DISPLAY_WELCOME_MESSAGE_TIME,0);
 713  00fa 5f            	clrw	x
 714  00fb 89            	pushw	x
 715  00fc ae07d0        	ldw	x,#2000
 716  00ff 89            	pushw	x
 717  0100 4f            	clr	a
 718  0101 cd0000        	call	_vtimer_SetTimer
 720  0104 5b04          	addw	sp,#4
 722  0106               L304:
 723                     ; 203   while (!(vtimer_TimerElapsed(VTIM_KEY)));
 725  0106 4f            	clr	a
 726  0107 cd0000        	call	_vtimer_TimerElapsed
 728  010a 4d            	tnz	a
 729  010b 27f9          	jreq	L304
 730                     ; 204 	vtimer_SetTimer(VTIM_DISPLAY_BLINK,DISPLAY_BLINKING_TIME,0); // Used for set point blinking
 732  010d 5f            	clrw	x
 733  010e 89            	pushw	x
 734  010f ae012c        	ldw	x,#300
 735  0112 89            	pushw	x
 736  0113 a601          	ld	a,#1
 737  0115 cd0000        	call	_vtimer_SetTimer
 739  0118 5b04          	addw	sp,#4
 740                     ; 206   return NEXT_STATE;
 742  011a a601          	ld	a,#1
 745  011c 85            	popw	x
 746  011d 81            	ret	
 831                     ; 209 SM_RetVal_t sm_idle(void)
 831                     ; 210 {
 832                     	switch	.text
 833  011e               _sm_idle:
 835  011e 5203          	subw	sp,#3
 836       00000003      OFST:	set	3
 839                     ; 211   SM_RetVal_t sm_retVal = STATE_REMAIN;
 841  0120 0f03          	clr	(OFST+0,sp)
 842                     ; 216   driveIdle();
 844  0122 cd0000        	call	_driveIdle
 846                     ; 217   hwRetVal = devChkHWErr();
 848  0125 cd0000        	call	_devChkHWErr
 850  0128 6b02          	ld	(OFST-1,sp),a
 851                     ; 229 	kpRetVal = keysProcess();
 853  012a cd0000        	call	_keysProcess
 855  012d 6b01          	ld	(OFST-2,sp),a
 856                     ; 234   if (hwRetVal == FUNCTION_ERROR)
 858  012f 7b02          	ld	a,(OFST-1,sp)
 859  0131 a102          	cp	a,#2
 860  0133 2604          	jrne	L744
 861                     ; 236     sm_retVal = ERROR_CONDITION;
 863  0135 a603          	ld	a,#3
 865  0137 2008          	jp	LC002
 866  0139               L744:
 867                     ; 240   else if (kpRetVal == USER_SEL)
 869  0139 7b01          	ld	a,(OFST-2,sp)
 870  013b a107          	cp	a,#7
 871  013d 2604          	jrne	L154
 872                     ; 242     sm_retVal = NEXT_STATE; 
 874  013f a601          	ld	a,#1
 875  0141               LC002:
 876  0141 6b03          	ld	(OFST+0,sp),a
 877  0143               L154:
 878                     ; 246   return sm_retVal;
 880  0143 7b03          	ld	a,(OFST+0,sp)
 883  0145 5b03          	addw	sp,#3
 884  0147 81            	ret	
 954                     ; 249 SM_RetVal_t sm_startinit(void)
 954                     ; 250 {
 955                     	switch	.text
 956  0148               _sm_startinit:
 958  0148 5204          	subw	sp,#4
 959       00000004      OFST:	set	4
 962                     ; 251   SM_RetVal_t sm_retVal = STATE_REMAIN;
 964  014a 0f04          	clr	(OFST+0,sp)
 965                     ; 256   retVal = driveStartUpInit();
 967  014c cd0000        	call	_driveStartUpInit
 969  014f 6b03          	ld	(OFST-1,sp),a
 970                     ; 257   hwRetVal = devChkHWErr();
 972  0151 cd0000        	call	_devChkHWErr
 974  0154 6b02          	ld	(OFST-2,sp),a
 975                     ; 258   kpRetVal = keysProcess();
 977  0156 cd0000        	call	_keysProcess
 979  0159 6b01          	ld	(OFST-3,sp),a
 980                     ; 261   if (hwRetVal == FUNCTION_ERROR)
 982  015b 7b02          	ld	a,(OFST-2,sp)
 983  015d a102          	cp	a,#2
 984  015f 2604          	jrne	L705
 985                     ; 263     sm_retVal = ERROR_CONDITION;
 987  0161 a603          	ld	a,#3
 989  0163 2024          	jp	LC003
 990  0165               L705:
 991                     ; 267   else if (retVal == FUNCTION_ERROR) 
 993  0165 7b03          	ld	a,(OFST-1,sp)
 994  0167 a102          	cp	a,#2
 995  0169 260e          	jrne	L315
 996                     ; 269     sm_retVal = ERROR_CONDITION;
 998  016b a603          	ld	a,#3
 999  016d 6b04          	ld	(OFST+0,sp),a
1000                     ; 272     FaultingState = SM_STARTINIT_FAULT;
1002  016f 35030001      	mov	L5_FaultingState,#3
1003                     ; 274     UserInterface_Fault(MOTOR_IS_RUNNING);    
1005  0173 4c            	inc	a
1006  0174 cd0000        	call	_UserInterface_Fault
1009  0177 2012          	jra	L115
1010  0179               L315:
1011                     ; 276   else if (kpRetVal == USER_SEL)
1013  0179 7b01          	ld	a,(OFST-3,sp)
1014  017b a107          	cp	a,#7
1015  017d 2604          	jrne	L715
1016                     ; 278     sm_retVal = OPTIONAL_JUMP; 
1018  017f a602          	ld	a,#2
1020  0181 2006          	jp	LC003
1021  0183               L715:
1022                     ; 282   else if (retVal == FUNCTION_ENDED)
1024  0183 7b03          	ld	a,(OFST-1,sp)
1025  0185 4a            	dec	a
1026  0186 2603          	jrne	L115
1027                     ; 284     sm_retVal = NEXT_STATE;
1029  0188 4c            	inc	a
1030  0189               LC003:
1031  0189 6b04          	ld	(OFST+0,sp),a
1032  018b               L115:
1033                     ; 290   return sm_retVal;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -