Annotation of hatari/tests/serial/midi_ser.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Hatari MIDI port test
                      3:  *
                      4:  * Based on the file midi.c from EmuTOS:
                      5:  * Copyright (C) 2001-2016 Martin Doering
                      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: /* constants for the ACIA registers */
                     14: 
                     15: /* baudrate selection and reset (Baudrate = clock/factor) */
                     16: #define ACIA_DIV1  0
                     17: #define ACIA_DIV16 1
                     18: #define ACIA_DIV64 2
                     19: #define ACIA_RESET 3
                     20: 
                     21: /* character format */
                     22: #define ACIA_D7E2S (0<<2)       /* 7 data, even parity, 2 stop */
                     23: #define ACIA_D7O2S (1<<2)       /* 7 data, odd parity, 2 stop */
                     24: #define ACIA_D7E1S (2<<2)       /* 7 data, even parity, 1 stop */
                     25: #define ACIA_D7O1S (3<<2)       /* 7 data, odd parity, 1 stop */
                     26: #define ACIA_D8N2S (4<<2)       /* 8 data, no parity, 2 stop */
                     27: #define ACIA_D8N1S (5<<2)       /* 8 data, no parity, 1 stop */
                     28: #define ACIA_D8E1S (6<<2)       /* 8 data, even parity, 1 stop */
                     29: #define ACIA_D8O1S (7<<2)       /* 8 data, odd parity, 1 stop */
                     30: 
                     31: /* transmit control */
                     32: #define ACIA_RLTID (0<<5)       /* RTS low, TxINT disabled */
                     33: #define ACIA_RLTIE (1<<5)       /* RTS low, TxINT enabled */
                     34: #define ACIA_RHTID (2<<5)       /* RTS high, TxINT disabled */
                     35: #define ACIA_RLTIDSB (3<<5)     /* RTS low, TxINT disabled, send break */
                     36: 
                     37: /* receive control */
                     38: #define ACIA_RID (0<<7)         /* RxINT disabled */
                     39: #define ACIA_RIE (1<<7)         /* RxINT enabled */
                     40: 
                     41: /* status fields of the ACIA */
                     42: #define ACIA_RDRF 1             /* Receive Data Register Full */
                     43: #define ACIA_TDRE (1<<1)        /* Transmit Data Register Empty */
                     44: #define ACIA_DCD  (1<<2)        /* Data Carrier Detect */
                     45: #define ACIA_CTS  (1<<3)        /* Clear To Send */
                     46: #define ACIA_FE   (1<<4)        /* Framing Error */
                     47: #define ACIA_OVRN (1<<5)        /* Receiver Overrun */
                     48: #define ACIA_PE   (1<<6)        /* Parity Error */
                     49: #define ACIA_IRQ  (1<<7)        /* Interrupt Request */
                     50: 
                     51: struct ACIA
                     52: {
                     53:        unsigned char  ctrl;
                     54:        unsigned char  dummy1;
                     55:        unsigned char  data;
                     56:        unsigned char  dummy2;
                     57: };
                     58: 
                     59: #define ACIA_MIDI_BASE (0xfffffc04L)
                     60: #define midi_acia (*(volatile struct ACIA*)ACIA_MIDI_BASE)
                     61: 
                     62: /* can we send a byte to the MIDI ACIA ? */
                     63: long bcostat3(void)
                     64: {
                     65:        if (midi_acia.ctrl & ACIA_TDRE)
                     66:        {
                     67:                return -1;  /* OK */
                     68:        }
                     69:        else
                     70:        {
                     71:                /* Data register not empty */
                     72:                return 0;   /* not OK */
                     73:        }
                     74: }
                     75: 
                     76: /* send a byte to the MIDI ACIA */
                     77: long bconout3(char c)
                     78: {
                     79:        while(!bcostat3())
                     80:                ;
                     81: 
                     82:        midi_acia.data = c;
                     83:        return 1L;
                     84: }
                     85: 
                     86: /*==== midi_init - initialize the MIDI acia ==================*/
                     87: /*
                     88:  *  Enable receive interrupts, set the clock for 31.25 kbaud
                     89:  */
                     90: void midi_init(void)
                     91: {
                     92:        /* initialize midi ACIA */
                     93:        midi_acia.ctrl = ACIA_RESET;    /* master reset */
                     94: 
                     95:        midi_acia.ctrl = ACIA_RIE|      /* enable RxINT */
                     96:                         ACIA_RLTID|    /* RTS low, TxINT disabled */
                     97:                         ACIA_DIV16|    /* clock/16 */
                     98:                         ACIA_D8N1S;    /* 8 bit, 1 stop, no parity */
                     99: }
                    100: 
                    101: int main(int argc, char *argv[])
                    102: {
                    103:        char text[] = "The quick brown fox\njumps over the lazy dog\n";
                    104:        int i;
                    105:        void *sp = (void*)Super(0);
                    106: 
                    107:        midi_init();
                    108: 
                    109:        for (i = 0; text[i] != 0; i++)
                    110:                bconout3(text[i]);
                    111: 
                    112:        Super(sp);
                    113: 
                    114:        return 0;
                    115: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.