We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Iam using Keil MDK V4.20.03.0. I have referred "SWI Functions" under Keil Help for trying to invoke software interrupt from my C code as shown below,
#include <LPC23xx.H> unsigned int VAL = 0x000000a5; int __SWI(0) SWICall(unsigned int); int __SWI_0(unsigned int VAL) { return VAL; } void init(void){ PINSEL4 = 0x00000000; FIO2DIR = 0x000000ff; FIO2PIN = SWICall(); } int main(void){ init(); while(1){ FIO2PIN = 0x000000aa; delay(); FIO2PIN = 0x00000055; delay(); } }
I have also included the SWI.s file from C:\Keil\startup\ , within which i have uncommented the code statements related to SWI 0
SWI_Cnt EQU (SWI_End-SWI_Table)/4 SWI_Count DCD SWI_Cnt ; Import user SWI functions here. IMPORT __SWI_0 ;IMPORT __SWI_1 ;IMPORT __SWI_2 SWI_Table ; Insert user SWI functions here DCD __SWI_0 ; SWI 0 Function Entry ; DCD __SWI_1 ; SWI 1 Function Entry ; DCD __SWI_2 ; SWI 2 Function Entry SWI_End
But, i see the following errors/warnings which i am unable to resolve, Build target 'Target 1' assembling LPC2300.s... compiling switest.c... switest.c(5): error: #79: expected a type specifier switest.c(5): error: #141-D: unnamed prototyped parameters not allowed when body is present switest.c(5): error: #130: expected a "{" switest.c(8): warning: #12-D: parsing restarts here after previous syntax error switest.c(16): warning: #223-D: function "SWICall" declared implicitly switest.c(24): warning: #223-D: function "delay" declared implicitly assembling SWI.s... Target not created Request your valuable suggestions to help me resolve this problem.
Thanks, i have applied the changes and the code compiled fine but, upon execution of the SWI call,i.e. during context restore from the stack the processor is going into Pre-fetch abort state.
unsigned int __swi(0) SWICall(unsigned int); unsigned int __SWI_0(unsigned int VAL) { return (VAL); } void init(void){ unsigned int VAL = 0x000000a5; PINSEL4 = 0x00000000; FIO2DIR = 0x000000ff; FIO2PIN = SWICall(VAL);
Changes applied to startup.s file
Undef_Handler B Undef_Handler ;SWI_Handler B SWI_Handler IMPORT SWI_Handler PAbt_Handler B PAbt_Handler DAbt_Handler B DAbt_Handler
What kind of SWI_Handler are you using? Do you have your own?
If you are using RTX then it already provides a SWI_Handler but the first 8 SWI calls (SWI0..7) are reserved for RTX. User SWI calls start from number 8.
Change you SWI to 8 (or higher) in this case.
I have written my own SWI_Handler for familiarization. Iam not using Keil RTX.
unsigned int __SWI_0(unsigned int VAL) { return (VAL); }
Are any changes needed to the SWI.s file ?
; Import user SWI functions here. IMPORT __SWI_0 ;IMPORT __SWI_1 ;IMPORT __SWI_2 SWI_Table ; Insert user SWI functions here DCD __SWI_0 ; SWI 0 Function Entry ;DCD __SWI_1 ; SWI 1 Function Entry ;DCD __SWI_2 ; SWI 2 Function Entry SWI_End
Check if you have enough stack defined for Supervisor Mode (Stack Configuration in startup file).
You are correct,Thanks. Setting the appropriate stack size for the SVC mode has resolved the issue.