Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ch32v00x.h"
- volatile uint32_t cnt = 0;
- uint32_t result;
- //#define NESTING
- #ifdef NESTING
- void __attribute__((interrupt("WCH-Interrupt-fast"))) SW_Handler(void){ // #14
- cnt++;
- EXTI->INTENR |= EXTI_INTENR_MR0;
- EXTI->SWIEVR |= EXTI_SWIEVR_SWIEVR0;
- while(1){
- if(!(EXTI->SWIEVR & EXTI_SWIEVR_SWIEVR0))
- EXTI->SWIEVR |= EXTI_SWIEVR_SWIEVR0;
- }
- }
- void __attribute__((interrupt("WCH-Interrupt-fast"))) EXTI7_0_IRQHandler(void){ // #20
- EXTI->INTFR = EXTI_INTF_INTF0;
- }
- void main(void){
- __asm volatile("csrr %0,0x804" : "=r"(result)); // что в настройках стартапа?
- NVIC_SetPriority(Software_IRQn, 0b10 << 6); //#14 IPRIOR14 [7:6] <- 0x10
- NVIC_SetPriority(EXTI7_0_IRQn, 0b00 << 6); //#20 IPRIOR20 [7:6] <- 0x01
- NVIC_EnableIRQ(Software_IRQn);
- NVIC_EnableIRQ(EXTI7_0_IRQn);
- SysTick->CTLR |= (uint32_t)(1 << 0); // вкл SysTick
- SysTick->CTLR |= (uint32_t)(1 << 31); // вкл SWI
- while(1){
- }
- }
- #else
- void __attribute__((interrupt("WCH-Interrupt-fast"))) SW_Handler(void){ // #14
- cnt++;
- }
- void __attribute__((interrupt("WCH-Interrupt-fast"))) EXTI7_0_IRQHandler(void){ // #20
- EXTI->INTFR = EXTI_INTF_INTF0;
- }
- void main(void){
- __asm volatile("csrr %0,0x804" : "=r"(result)); // чтение
- __asm volatile("fence");
- __asm volatile("csrrw %0, 0x804, %1" : "=r"(result) :"r"(0x1)); //чтение - запись
- __asm volatile("csrr %0,0x804" : "=r"(result)); // что в настройках стартапа?
- __disable_irq();
- EXTI->INTENR |= EXTI_INTENR_MR0;
- EXTI->SWIEVR |= EXTI_SWIEVR_SWIEVR0;
- SysTick->CTLR |= (uint32_t)(1 << 0); // вкл SysTick
- SysTick->CTLR |= (uint32_t)(1 << 31); // вкл SWI
- NVIC_SetPriority(Software_IRQn, 0b10 << 6); //#14 IPRIOR14 [7:6] <- 0x10
- NVIC_SetPriority(EXTI7_0_IRQn, 0b01 << 6); //#20 IPRIOR20 [7:6] <- 0x01
- NVIC_EnableIRQ(Software_IRQn);
- NVIC_EnableIRQ(EXTI7_0_IRQn);
- __enable_irq();
- while(1){
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement