📄 1553_junk_bm-5_bu.c
字号:
// file bu.c
// BU-65550M2-605 PCMCIA card (1553) software
//
//
#include <sys/time.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "bu69080s1.h"
#include "bu.h"
reg_t *reg;
mem_t *mem;
int h;
int IRQ_installed = FALSE;
pthread_t thread;
extern int errno;
typedef struct {
int a;
int b;
} junk_t;
junk_t some__junk;
void buopen(void);
void buclose(void);
void ISR(junk_t *some_junk);
extern void bu_interrupt_handler(int16 interrupt_status);
//-----------------------------------------------------------------------------
void buopen(void) {
printf("\n***** it is buopen *****\n");
IRQ_installed = FALSE;
errno = 0;
h = open("/dev/bu69080s1", O_RDWR);
if (errno) {
perror("open /dev/bu69080s1");
exit(1);
}
errno = 0;
reg = mmap(0, ACE_CHAN_REG_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, h, 0);
if (errno) {
perror("mmap ACE_CHAN_REG");
exit(1);
}
errno = 0;
mem = mmap(0, ACE_CHAN_MEM_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, h, 0);
if (errno) {
perror("mmap ACE_CHAN_MEM");
exit(1);
}
reg->start_reset = 0x0001;
reg->config_2 = 0x8008 | BU_TIMETAG_2;
reg->config_3 = 0x8000;
reg->config_5 = 0xC000;
reg->interrupt_mask = 0x0000;
// Install Interrupts
errno = 0;
ioctl(h, IOCTL_ACE53_INSTALL_IRQ, NULL);
if (errno) {
perror("ioctl ACE53_INSTALL");
exit(1);
}
// Create Thread
some__junk.a = 123;
if (pthread_create(&thread, NULL, (void*)ISR, &some__junk)) {
printf("BU_ERROR_LINUX_IRQ_INSTALL_FAILED\n");
exit(1);
}
IRQ_installed = TRUE;
}
//-----------------------------------------------------------------------------
void buclose(void) {
printf("\n***** it is buclose *****\n");
reg->start_reset = 0x0001; // reset
if (IRQ_installed) {
IRQ_installed = FALSE;
// UnInstall Interrupts
errno = 0;
ioctl(h, IOCTL_ACE53_UNINSTALL_IRQ, NULL);
if (errno) {
perror("ioctl ACE53_UNINSTALL");
return;
}
pthread_join(thread, NULL);
}
close(h);
}
//-----------------------------------------------------------------------------
void ISR(junk_t *some_junk) {
int16 interrupt_status;
printf("***** it is ISR (1) %d\n", some_junk->a);
while (1) {
// Block on interrupts
errno = 0;
ioctl(h, IOCTL_ACE53_BLOCK_IN_DRIVER, &interrupt_status);
if (errno) {
perror("ioctl ACE53_BLOCK");
pthread_exit((void*)-1);
}
/*
printf("***** it is ISR (2) c=%d: m=0x%04X s=0x%04X",
some_junk->a, reg->interrupt_mask, interrupt_status);
if (interrupt_status & 0x0C00) printf(" OVF\n");
else printf("\n");
some_junk->a++;
*/
bu_interrupt_handler(interrupt_status);
// If uninstalling, clean up thread
if (IRQ_installed == FALSE) {
printf("***** it is ISR (3)\n");
pthread_exit(NULL);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -