1*bacd691cSlogin use core::{ptr::null_mut, sync::atomic::{AtomicBool, Ordering}}; 2*bacd691cSlogin 3*bacd691cSlogin use alloc::sync::Arc; 4*bacd691cSlogin 5*bacd691cSlogin use crate::{ 6*bacd691cSlogin exception::softirq::{SoftirqNumber, SoftirqVec, softirq_vectors}, 7*bacd691cSlogin include::bindings::bindings::video_refresh_framebuffer, 8*bacd691cSlogin }; 9*bacd691cSlogin 10*bacd691cSlogin #[derive(Debug)] 11*bacd691cSlogin pub struct VideoRefreshFramebuffer{ 12*bacd691cSlogin running: AtomicBool 13*bacd691cSlogin } 14*bacd691cSlogin 15*bacd691cSlogin impl SoftirqVec for VideoRefreshFramebuffer { 16*bacd691cSlogin fn run(&self) { 17*bacd691cSlogin if self.set_run() == false{ 18*bacd691cSlogin return; 19*bacd691cSlogin } 20*bacd691cSlogin 21*bacd691cSlogin unsafe { 22*bacd691cSlogin video_refresh_framebuffer(null_mut()); 23*bacd691cSlogin } 24*bacd691cSlogin 25*bacd691cSlogin self.clear_run(); 26*bacd691cSlogin } 27*bacd691cSlogin } 28*bacd691cSlogin impl VideoRefreshFramebuffer { 29*bacd691cSlogin pub fn new() -> VideoRefreshFramebuffer { 30*bacd691cSlogin VideoRefreshFramebuffer { 31*bacd691cSlogin running: AtomicBool::new(false) 32*bacd691cSlogin } 33*bacd691cSlogin } 34*bacd691cSlogin 35*bacd691cSlogin fn set_run(&self) -> bool { 36*bacd691cSlogin let x = self 37*bacd691cSlogin .running 38*bacd691cSlogin .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed); 39*bacd691cSlogin if x.is_ok() { 40*bacd691cSlogin return true; 41*bacd691cSlogin } else { 42*bacd691cSlogin return false; 43*bacd691cSlogin } 44*bacd691cSlogin } 45*bacd691cSlogin 46*bacd691cSlogin fn clear_run(&self) { 47*bacd691cSlogin self.running.store(false, Ordering::Release); 48*bacd691cSlogin } 49*bacd691cSlogin } 50*bacd691cSlogin 51*bacd691cSlogin pub fn register_softirq_video() { 52*bacd691cSlogin // kdebug!("register_softirq_video"); 53*bacd691cSlogin let handler = Arc::new(VideoRefreshFramebuffer::new()); 54*bacd691cSlogin softirq_vectors() 55*bacd691cSlogin .register_softirq(SoftirqNumber::VideoRefresh, handler) 56*bacd691cSlogin .expect("register_softirq_video run failed"); 57*bacd691cSlogin } 58*bacd691cSlogin // ======= 以下为给C提供的接口,video重构完后请删除 ======= 59*bacd691cSlogin #[no_mangle] 60*bacd691cSlogin pub extern "C" fn rs_register_softirq_video() { 61*bacd691cSlogin register_softirq_video(); 62*bacd691cSlogin } 63