BASIC compiler/interpreter for PIC32MX/MZ-80K
Revision | 5a625009f29bc655ee8e57a23fe50811e929cbb0 (tree) |
---|---|
Zeit | 2019-04-14 15:57:33 |
Autor | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
MZP: coretimer implementations.
@@ -70,6 +70,7 @@ void stop_timer(){ | ||
70 | 70 | IEC0bits.T1IE=0; |
71 | 71 | // Disable interrupt |
72 | 72 | IEC0bits.CS1IE=0; |
73 | + IEC0bits.CTIE=0; | |
73 | 74 | } |
74 | 75 | |
75 | 76 | /* |
@@ -280,6 +280,7 @@ char* fput_statement(); | ||
280 | 280 | char* fputc_statement(); |
281 | 281 | char* fremove_statement(); |
282 | 282 | char* label_statement(); |
283 | +char* exec_statement(); | |
283 | 284 | |
284 | 285 | char* function(void); |
285 | 286 | char* str_function(void); |
@@ -375,6 +376,8 @@ void stop_timer(); | ||
375 | 376 | char* usetimer_statement(); |
376 | 377 | char* timer_statement(); |
377 | 378 | char* timer_function(); |
379 | +char* coretimer_statement(); | |
380 | +char* coretimer_function(); | |
378 | 381 | char* interrupt_statement(); |
379 | 382 | |
380 | 383 | /* Error messages */ |
@@ -493,6 +496,7 @@ char* interrupt_statement(); | ||
493 | 496 | #define INTERRUPT_INKEY 3 |
494 | 497 | #define INTERRUPT_MUSIC 4 |
495 | 498 | #define INTERRUPT_WAVE 5 |
499 | +#define INTERRUPT_CORETIMER 6 | |
496 | 500 | |
497 | 501 | extern int g_interrupt_flags; |
498 | 502 | extern int g_int_vector[]; |
@@ -391,6 +391,10 @@ char* getdir_function(){ | ||
391 | 391 | return 0; |
392 | 392 | } |
393 | 393 | |
394 | +char* exec_function(){ | |
395 | + return exec_statement(); | |
396 | +} | |
397 | + | |
394 | 398 | char* float_constant(float val){ |
395 | 399 | volatile int i; |
396 | 400 | ((float*)(&i))[0]=val; |
@@ -597,6 +601,8 @@ static const void* int_func_list[]={ | ||
597 | 601 | "NEW(",new_function, |
598 | 602 | "SETDIR(",setdir_function, |
599 | 603 | "TIMER(",timer_function, |
604 | + "EXEC(",exec_function, | |
605 | + "CORETIMER(",coretimer_function, | |
600 | 606 | // Additional functions follow |
601 | 607 | ADDITIONAL_INT_FUNCTIONS |
602 | 608 | }; |
@@ -1741,6 +1741,7 @@ static const void* statement_list[]={ | ||
1741 | 1741 | "TIMER ",timer_statement, |
1742 | 1742 | "INTERRUPT ",interrupt_statement, |
1743 | 1743 | "IDLE",idle_statement, |
1744 | + "CORETIMER",coretimer_statement, | |
1744 | 1745 | // List of additional statements follows |
1745 | 1746 | ADDITIONAL_STATEMENTS |
1746 | 1747 | }; |
@@ -33,6 +33,7 @@ static const void* interrupt_list[]={ | ||
33 | 33 | "INKEY", (void*)INTERRUPT_INKEY, |
34 | 34 | "MUSIC", (void*)INTERRUPT_MUSIC, |
35 | 35 | "WAVE", (void*)INTERRUPT_WAVE, |
36 | + "CORETIMER",(void*)INTERRUPT_CORETIMER, | |
36 | 37 | ADDITIONAL_INTERRUPT_FUNCTIONS |
37 | 38 | }; |
38 | 39 | #define NUM_INTERRUPT_TYPES ((sizeof(interrupt_list)/sizeof(interrupt_list[0]))/2) |
@@ -69,6 +70,7 @@ void stop_timer(){ | ||
69 | 70 | IEC0bits.T1IE=0; |
70 | 71 | // Disable interrupt |
71 | 72 | IEC0bits.CS1IE=0; |
73 | + IEC0bits.CTIE=0; | |
72 | 74 | } |
73 | 75 | |
74 | 76 | /* |
@@ -157,6 +159,40 @@ char* timer_function(){ | ||
157 | 159 | } |
158 | 160 | |
159 | 161 | /* |
162 | + Coretimer implementaion | |
163 | +*/ | |
164 | + | |
165 | +#pragma interrupt CTHandler IPL2SOFT vector 0 | |
166 | +void CTHandler(void){ | |
167 | + // Clear CT interrupt flag | |
168 | + IFS0bits.CTIF=0; | |
169 | + // Raise TIMER interrupt flag | |
170 | + raise_interrupt_flag(INTERRUPT_CORETIMER); | |
171 | +} | |
172 | + | |
173 | +char* coretimer_function(){ | |
174 | + check_obj_space(1); | |
175 | + g_object[g_objpos++]=0x40024800; // mfc0 v0,Count | |
176 | + return 0; | |
177 | +} | |
178 | + | |
179 | +void lib_coretimer(){ | |
180 | + // CT interrupt: priority 2 | |
181 | + IPC0bits.CTIP=2; | |
182 | + IPC0bits.CTIS=0; | |
183 | + IEC0bits.CTIE=1; | |
184 | +} | |
185 | + | |
186 | +char* coretimer_statement(){ | |
187 | + char* err; | |
188 | + err=get_value(); | |
189 | + if (err) return err; | |
190 | + // 0x40825800: mtc0 v0,Compare | |
191 | + call_quicklib_code(lib_coretimer,0x40825800); | |
192 | + return 0; | |
193 | +} | |
194 | + | |
195 | +/* | |
160 | 196 | Interrupt interprtation |
161 | 197 | To cause interruption, use raise_interrupt_flag() macro |
162 | 198 | For example, |
@@ -280,6 +280,7 @@ char* fput_statement(); | ||
280 | 280 | char* fputc_statement(); |
281 | 281 | char* fremove_statement(); |
282 | 282 | char* label_statement(); |
283 | +char* exec_statement(); | |
283 | 284 | |
284 | 285 | char* function(void); |
285 | 286 | char* str_function(void); |
@@ -375,6 +376,8 @@ void stop_timer(); | ||
375 | 376 | char* usetimer_statement(); |
376 | 377 | char* timer_statement(); |
377 | 378 | char* timer_function(); |
379 | +char* coretimer_statement(); | |
380 | +char* coretimer_function(); | |
378 | 381 | char* interrupt_statement(); |
379 | 382 | |
380 | 383 | /* Error messages */ |
@@ -493,6 +496,7 @@ char* interrupt_statement(); | ||
493 | 496 | #define INTERRUPT_INKEY 3 |
494 | 497 | #define INTERRUPT_MUSIC 4 |
495 | 498 | #define INTERRUPT_WAVE 5 |
499 | +#define INTERRUPT_CORETIMER 6 | |
496 | 500 | |
497 | 501 | extern int g_interrupt_flags; |
498 | 502 | extern int g_int_vector[]; |
@@ -391,6 +391,10 @@ char* getdir_function(){ | ||
391 | 391 | return 0; |
392 | 392 | } |
393 | 393 | |
394 | +char* exec_function(){ | |
395 | + return exec_statement(); | |
396 | +} | |
397 | + | |
394 | 398 | char* float_constant(float val){ |
395 | 399 | volatile int i; |
396 | 400 | ((float*)(&i))[0]=val; |
@@ -597,6 +601,8 @@ static const void* int_func_list[]={ | ||
597 | 601 | "NEW(",new_function, |
598 | 602 | "SETDIR(",setdir_function, |
599 | 603 | "TIMER(",timer_function, |
604 | + "EXEC(",exec_function, | |
605 | + "CORETIMER(",coretimer_function, | |
600 | 606 | // Additional functions follow |
601 | 607 | ADDITIONAL_INT_FUNCTIONS |
602 | 608 | }; |
@@ -1741,6 +1741,7 @@ static const void* statement_list[]={ | ||
1741 | 1741 | "TIMER ",timer_statement, |
1742 | 1742 | "INTERRUPT ",interrupt_statement, |
1743 | 1743 | "IDLE",idle_statement, |
1744 | + "CORETIMER",coretimer_statement, | |
1744 | 1745 | // List of additional statements follows |
1745 | 1746 | ADDITIONAL_STATEMENTS |
1746 | 1747 | }; |
@@ -33,6 +33,7 @@ static const void* interrupt_list[]={ | ||
33 | 33 | "INKEY", (void*)INTERRUPT_INKEY, |
34 | 34 | "MUSIC", (void*)INTERRUPT_MUSIC, |
35 | 35 | "WAVE", (void*)INTERRUPT_WAVE, |
36 | + "CORETIMER",(void*)INTERRUPT_CORETIMER, | |
36 | 37 | ADDITIONAL_INTERRUPT_FUNCTIONS |
37 | 38 | }; |
38 | 39 | #define NUM_INTERRUPT_TYPES ((sizeof(interrupt_list)/sizeof(interrupt_list[0]))/2) |
@@ -69,6 +70,7 @@ void stop_timer(){ | ||
69 | 70 | IEC0bits.T1IE=0; |
70 | 71 | // Disable interrupt |
71 | 72 | IEC0bits.CS1IE=0; |
73 | + IEC0bits.CTIE=0; | |
72 | 74 | } |
73 | 75 | |
74 | 76 | /* |
@@ -157,6 +159,40 @@ char* timer_function(){ | ||
157 | 159 | } |
158 | 160 | |
159 | 161 | /* |
162 | + Coretimer implementaion | |
163 | +*/ | |
164 | + | |
165 | +#pragma interrupt CTHandler IPL2SOFT vector 0 | |
166 | +void CTHandler(void){ | |
167 | + // Clear CT interrupt flag | |
168 | + IFS0bits.CTIF=0; | |
169 | + // Raise TIMER interrupt flag | |
170 | + raise_interrupt_flag(INTERRUPT_CORETIMER); | |
171 | +} | |
172 | + | |
173 | +char* coretimer_function(){ | |
174 | + check_obj_space(1); | |
175 | + g_object[g_objpos++]=0x40024800; // mfc0 v0,Count | |
176 | + return 0; | |
177 | +} | |
178 | + | |
179 | +void lib_coretimer(){ | |
180 | + // CT interrupt: priority 2 | |
181 | + IPC0bits.CTIP=2; | |
182 | + IPC0bits.CTIS=0; | |
183 | + IEC0bits.CTIE=1; | |
184 | +} | |
185 | + | |
186 | +char* coretimer_statement(){ | |
187 | + char* err; | |
188 | + err=get_value(); | |
189 | + if (err) return err; | |
190 | + // 0x40825800: mtc0 v0,Compare | |
191 | + call_quicklib_code(lib_coretimer,0x40825800); | |
192 | + return 0; | |
193 | +} | |
194 | + | |
195 | +/* | |
160 | 196 | Interrupt interprtation |
161 | 197 | To cause interruption, use raise_interrupt_flag() macro |
162 | 198 | For example, |