|
|
1.1 ! root 1: /* ! 2: * Hatari serial port test ! 3: * ! 4: * Partly based on the file serport.c and mfp.h from EmuTOS: ! 5: * Copyright (C) 2013-2018 The EmuTOS development team ! 6: * ! 7: * This file is distributed under the GPL, version 2 or at your ! 8: * option any later version. See doc/license.txt for details. ! 9: */ ! 10: ! 11: #include <tos.h> ! 12: ! 13: typedef unsigned char UBYTE; ! 14: ! 15: /*==== MFP memory mapping =================================================*/ ! 16: typedef struct ! 17: { ! 18: UBYTE dum1; ! 19: volatile UBYTE gpip; /* general purpose .. register */ ! 20: UBYTE dum2; ! 21: volatile UBYTE aer; /* active edge register */ ! 22: UBYTE dum3; ! 23: volatile UBYTE ddr; /* data direction register */ ! 24: UBYTE dum4; ! 25: volatile UBYTE iera; /* interrupt enable register A */ ! 26: UBYTE dum5; ! 27: volatile UBYTE ierb; /* interrupt enable register B */ ! 28: UBYTE dum6; ! 29: volatile UBYTE ipra; /* interrupt pending register A */ ! 30: UBYTE dum7; ! 31: volatile UBYTE iprb; /* interrupt pending register B */ ! 32: UBYTE dum8; ! 33: volatile UBYTE isra; /* interrupt in-service register A */ ! 34: UBYTE dum9; ! 35: volatile UBYTE isrb; /* interrupt in-service register B */ ! 36: UBYTE dum10; ! 37: volatile UBYTE imra; /* interrupt mask register A */ ! 38: UBYTE dum11; ! 39: volatile UBYTE imrb; /* interrupt mask register B */ ! 40: UBYTE dum12; ! 41: volatile UBYTE vr; /* vector register */ ! 42: UBYTE dum13; ! 43: volatile UBYTE tacr; /* timer A control register */ ! 44: UBYTE dum14; ! 45: volatile UBYTE tbcr; /* timer B control register */ ! 46: UBYTE dum15; ! 47: volatile UBYTE tcdcr; /* timer C + D control register */ ! 48: UBYTE dum16; ! 49: volatile UBYTE tadr; /* timer A data register */ ! 50: UBYTE dum17; ! 51: volatile UBYTE tbdr; /* timer B data register */ ! 52: UBYTE dum18; ! 53: volatile UBYTE tcdr; /* timer C data register */ ! 54: UBYTE dum19; ! 55: volatile UBYTE tddr; /* timer D data register */ ! 56: UBYTE dum20; ! 57: volatile UBYTE scr; /* syncronous character register */ ! 58: UBYTE dum21; ! 59: volatile UBYTE ucr; /* USART control register */ ! 60: UBYTE dum22; ! 61: volatile UBYTE rsr; /* receiver status register */ ! 62: UBYTE dum23; ! 63: volatile UBYTE tsr; /* transmitter status register */ ! 64: UBYTE dum24; ! 65: volatile UBYTE udr; /* USART data register */ ! 66: } MFP; ! 67: ! 68: #define MFP_BASE ((MFP *)(0xfffffa00L)) ! 69: ! 70: /* ! 71: * MFP serial port i/o routines ! 72: */ ! 73: static long costat(void) ! 74: { ! 75: if (MFP_BASE->tsr & 0x80) ! 76: return -1; ! 77: else ! 78: return 0; ! 79: } ! 80: ! 81: static void conout(char b) ! 82: { ! 83: /* Wait for transmit buffer to become empty */ ! 84: while(!costat()) ! 85: ; ! 86: ! 87: /* Output to RS232 interface */ ! 88: MFP_BASE->udr = (char)b; ! 89: } ! 90: ! 91: int main(int argc, char *argv[]) ! 92: { ! 93: char text[] = "The quick brown fox\njumps over the lazy dog\n"; ! 94: int i; ! 95: void *sp = (void*)Super(0); ! 96: ! 97: MFP_BASE->scr = 0x00; ! 98: MFP_BASE->ucr = 0x88; ! 99: MFP_BASE->rsr = 0x01; ! 100: MFP_BASE->tsr = 0x01; ! 101: ! 102: for (i = 0; text[i] != 0; i++) ! 103: conout(text[i]); ! 104: ! 105: Super(sp); ! 106: ! 107: return 0; ! 108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.