1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-05-01 06:09:29 +00:00

DMA write fix

This commit is contained in:
harbaum
2013-05-08 14:30:20 +00:00
parent ef54a02298
commit c55835c4b4
3 changed files with 144 additions and 24 deletions

View File

@@ -105,6 +105,11 @@ void __init_hardware(void)
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
}
volatile int cnt = 0;
void __attribute__((naked)) Usart0IrqHandler (void) {
// cnt++;
}
void USART_Init(unsigned long baudrate)
{
// Configure PA5 and PA6 for USART0 use
@@ -124,6 +129,30 @@ void USART_Init(unsigned long baudrate)
// Enable receiver & transmitter
AT91C_BASE_US0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
#if 0
// configure tx irqs
// TODO: reset tx/rw pointers
// http://www.procyonengineering.com/embedded/arm/armlib/docs/html/uartdma_8c-source.html
// http://www.mikrocontroller.net/articles/DMA
// http://svn.code.sf.net/p/lejos/code/tags/lejos_nxj_0.9.0/nxtvm/platform/nxt/hs.c
// setup DMA controller for transmit
// AT91C_BASE_US0->US_TNPR = 0;
puts("Vorher");
// Set the USART0 IRQ handler address in AIC Source
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_US0] = (unsigned int)Usart0IrqHandler;
AT91C_BASE_AIC->AIC_IECR = (1<<AT91C_ID_US0);
AT91C_BASE_US0->US_IER = AT91C_US_ENDTX;
AT91C_BASE_US0->US_IDR = ~AT91C_US_ENDTX;
puts("Hallo3!");
for(;;);
#endif
}
RAMFUNC void USART_Write(unsigned char c)

87
ikbd.c
View File

@@ -15,6 +15,8 @@
Joysticks also generate Goldrunner X X
mouse button events!
Pause (cmd 0x13) Wings of Death/A_427
pause/resume Gembench
mouse keycode mode
*/
#include <stdio.h>
@@ -48,6 +50,8 @@ static struct {
unsigned char joystick[2];
// mouse state
unsigned short mouse_abs_max_x, mouse_abs_max_y;
unsigned char mouse_abs_scale_x, mouse_abs_scale_y;
unsigned short mouse_pos_x, mouse_pos_y;
unsigned char mouse_buttons;
} ikbd;
@@ -58,6 +62,9 @@ void ikbd_init() {
// reset ikbd state
memset(&ikbd, 0, sizeof(ikbd));
ikbd.state = IKBD_DEFAULT;
ikbd.mouse_abs_max_x = ikbd.mouse_abs_max_y = 65535;
ikbd.mouse_abs_scale_x = ikbd.mouse_abs_scale_y = 1;
}
static void enqueue(unsigned short b) {
@@ -101,6 +108,34 @@ void ikbd_handle_input(unsigned char cmd) {
break;
case 0x09:
if(ikbd.expect == 3) ikbd.mouse_abs_max_x = cmd;
if(ikbd.expect == 2) ikbd.mouse_abs_max_x = (ikbd.mouse_abs_max_x & 0xff00) | cmd;
if(ikbd.expect == 1) ikbd.mouse_abs_max_y = cmd;
if(ikbd.expect == 0) ikbd.mouse_abs_max_y = (ikbd.mouse_abs_max_y & 0xff00) | cmd;
if(!ikbd.expect)
iprintf("IKBD: new abs max = %u/%u\n", ikbd.mouse_abs_max_x, ikbd.mouse_abs_max_y);
break;
case 0x0e:
if(ikbd.expect == 3) ikbd.mouse_pos_x = cmd;
if(ikbd.expect == 2) ikbd.mouse_pos_x = (ikbd.mouse_pos_x & 0xff00) | cmd;
if(ikbd.expect == 1) ikbd.mouse_pos_y = cmd;
if(ikbd.expect == 0) ikbd.mouse_pos_y = (ikbd.mouse_pos_y & 0xff00) | cmd;
if(!ikbd.expect)
iprintf("IKBD: new abs pos = %u/%u\n", ikbd.mouse_pos_x, ikbd.mouse_pos_y);
break;
case 0x0c:
if(ikbd.expect == 1) ikbd.mouse_abs_scale_x = cmd;
if(ikbd.expect == 0) ikbd.mouse_abs_scale_y = cmd;
if(!ikbd.expect)
iprintf("IKBD: absolute scale = %u/%u\n", ikbd.mouse_abs_scale_x, ikbd.mouse_abs_scale_y);
break;
case 0x80: // ibkd reset
// reply "everything is ok"
enqueue(0x8000 + 200); // wait 200ms
@@ -141,6 +176,28 @@ void ikbd_handle_input(unsigned char cmd) {
ikbd.expect = 2;
break;
case 0x0c:
puts("IKBD: Set Mouse scale");
ikbd.expect = 2;
break;
case 0x0d:
puts("IKBD: Interrogate Mouse Position");
if(ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE) {
enqueue(0xf7);
enqueue(0x00); // TODO: Buttons
enqueue(ikbd.mouse_pos_x >> 8);
enqueue(ikbd.mouse_pos_x & 0xff);
enqueue(ikbd.mouse_pos_y >> 8);
enqueue(ikbd.mouse_pos_y & 0xff);
}
break;
case 0x0e:
puts("IKBD: Load Mouse Position");
ikbd.expect = 5;
break;
case 0x0f:
puts("IKBD: Set Y at bottom");
ikbd.state |= IKBD_STATE_MOUSE_Y_BOTTOM;
@@ -341,6 +398,36 @@ void ikbd_mouse(unsigned char b, char x, char y) {
y = -y;
if(ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE) {
x /= ikbd.mouse_abs_scale_x;
y /= ikbd.mouse_abs_scale_y;
if(x < 0) {
x = -x;
if(ikbd.mouse_pos_x > x) ikbd.mouse_pos_x -= x;
else ikbd.mouse_pos_x = 0;
}
if(x > 0) {
if(ikbd.mouse_pos_x < ikbd.mouse_abs_max_x - x)
ikbd.mouse_pos_x += x;
else
ikbd.mouse_pos_x = ikbd.mouse_abs_max_x;
}
if(y < 0) {
y = -y;
if(ikbd.mouse_pos_y > y) ikbd.mouse_pos_y -= y;
else ikbd.mouse_pos_y = 0;
}
if(y > 0) {
if(ikbd.mouse_pos_y < ikbd.mouse_abs_max_y - y)
ikbd.mouse_pos_y += y;
else
ikbd.mouse_pos_y = ikbd.mouse_abs_max_y;
}
} else {
// atari has mouse button bits swapped
enqueue(0xf8|((b&1)?2:0)|((b&2)?1:0));

52
tos.c
View File

@@ -96,12 +96,12 @@ static void mist_memory_read(char *data, unsigned long words) {
EnableFpga();
SPI(MIST_READ_MEMORY);
while (!(*AT91C_SPI_SR & AT91C_SPI_TDRE));
// while (!(*AT91C_SPI_SR & AT91C_SPI_TDRE));
// transmitted bytes must be multiple of 2 (-> words)
while(words--) {
*data++ = SPI_READ();
*data++ = SPI_READ();
*data++ = SPI(0);
*data++ = SPI(0);
}
DisableFpga();
@@ -513,8 +513,8 @@ void tos_upload(char *name) {
iprintf("]\n");
time = GetTimer(0) - time;
iprintf("TOS.IMG uploaded in %lu ms (%d kB/s)\r",
time >> 20, file.size/(time >> 20));
iprintf("TOS.IMG uploaded in %lu ms (%d kB/s / %d kBit/s)\r",
time >> 20, file.size/(time >> 20), 8*file.size/(time >> 20));
} else
iprintf("Unable to find tos.img\n");
@@ -567,27 +567,31 @@ void tos_upload(char *name) {
#endif
DISKLED_OFF;
// load
tos_load_cartridge(NULL);
// This is the initial boot if no name was given. Otherwise the
// user reloaded a new os
if(!name) {
// load
tos_load_cartridge(NULL);
// try to open both floppies
int i;
for(i=0;i<2;i++) {
char msg[] = "Found floppy disk image for drive X: ";
char name[] = "DISK_A ST ";
msg[34] = name[5] = 'A'+i;
fileTYPE file;
if(FileOpen(&file, name)) {
tos_write(msg);
tos_insert_disk(i, &file);
// try to open both floppies
int i;
for(i=0;i<2;i++) {
char msg[] = "Found floppy disk image for drive X: ";
char name[] = "DISK_A ST ";
msg[34] = name[5] = 'A'+i;
fileTYPE file;
if(FileOpen(&file, name)) {
tos_write(msg);
tos_insert_disk(i, &file);
}
}
// try to open harddisk image
if(FileOpen(&file, "HARDDISKHD ")) {
tos_write("Found hard disk image ");
tos_select_hdd_image(&file);
}
}
// try to open harddisk image
if(FileOpen(&file, "HARDDISKHD ")) {
tos_write("Found hard disk image ");
tos_select_hdd_image(&file);
}
tos_write("Booting ... ");