Other Parts Discussed in Thread: HALCOGEN
The problem I have is that I want to access the control registers of the mcu to start the time base clock for a pwm function I'm writing .
In Halcogen there's already a file generated to do that . But I need special access .I've attempted to write to access the privilege mode which is below
In CCS it throws an error saying Illegal mnemonic specified.
Can anybody figure this out.
*********************************************************************************
// SWI handler function
__attribute__((interrupt("SWI"))) void SWI_Handler(void)
{
// Call the FSYS_RaisePrivilege function
FSYS_RaisePrivilege();
}
int32_t FSYS_RaisePrivilege(void)
{
int32_t asm_result;
// Assembly code to raise privilege
__asm(
"mrs r12, spsr\n" // Copy SPSR into local register r12
"ands r0, r12, #0x0F\n" // Perform bitwise AND on r12 and 0x0F
"mov r1, r0\n" // Move result to r1 register
"orreq r12, r12, #0x1F\n" // Perform logical OR on r12 and 0x1F
"msreq spsr_c, r12\n" // Conditionally load result into control field mask byte
"mov %0, r1\n" // Move result to global variable asm_result
: "=r" (asm_result) // Output operand definition
: // No input operands
: "r0", "r1", "r12" // Clobbered registers
);
// Return the result stored in asm_result
return asm_result;
}
*******************************************************************************
this is another attempt below
*******************************************************************************
#include <stdint.h>
// Declare a global variable to store the result
//#pragma SWI_ALIAS(FSYS_RaisePrivilege, 1);
extern long FSYS_RaisePrivilege(void);
// SWI handler function
__attribute__((interrupt("SWI"))) void SWI_Handler(void)
{
// Call the FSYS_RaisePrivilege function
FSYS_RaisePrivilege();
}
#pragma FUNC_ALWAYS_INLINE(FSYS_SwitchToUserMode)
static inline void FSYS_SwitchToUserMode(void) {
__asm(" CPS #0x10");
}
extern long FSYS_RaisePrivilege()
{
__asm(" mrs r12, spsr");
__asm("ands r0, r12, #0x0F");
__asm("orreq r12, r12, #0x1F");
__asm("msreq spsr_c, r12");
__asm("bx r14");
}
***********************************************************************************************
why does the compiler not recognize the assembly code ?
Note I'm not using FreeRTOS.