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