X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=pkernel%2Fuart.c;h=71eb44ba8f6dd33610c584a7c03686c6c0b934fc;hb=0488126f3e78ba8682488cfc49d232d2762dd90f;hp=0c528ddfc1922afe4be1ecf225b086b9d45cc8a9;hpb=96324b051bfefe94b0887d30f1897ed21b25efff;p=pyfrprog.git diff --git a/pkernel/uart.c b/pkernel/uart.c index 0c528dd..71eb44b 100644 --- a/pkernel/uart.c +++ b/pkernel/uart.c @@ -1,101 +1,65 @@ -/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */ -/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */ -/* ELIGIBILITY FOR ANY PURPOSES. */ -/* (C) Fujitsu Microelectronics Europe GmbH */ -/*---------------------------------------------------------------------------*/ - #include "mb91465k.h" +#pragma section CODE=IRAM,attr=CODE const char ASCII[] = "0123456789ABCDEF"; void InitUart4(void) { - // Initialize UART asynchronous mode - // BGR04 = 1666; // 9600 Baud @ 16MHz - BGR04 = 832; // 19200 Baud @ 16MHz - // BGR04 = 416; // 38400 Baud @ 16MHz - - // BGR04 = 2083; // 9600 Baud @ 20MHz - // BGR04 = 1041; // 19200 Baud @ 20MHz - // BGR04 = 520; // 38400 Baud @ 20MHz - - // BGR04 = 2499; // 9600 Baud @ 24MHz - // BGR04 = 1249; // 19200 Baud @ 24MHz - // BGR04 = 624; // 38400 Baud @ 24MHz - SCR04 = 0x17; // 8N1 - SMR04 = 0x0d; // enable SOT3, Reset, normal mode - SSR04 = 0x00; // LSB first - PFR19 = (PFR19 & 0xFC) | 0x03; // enable UART: SIN,SOT for async. transfer - EPFR19 = 0x00; // enable UART + // Initialize UART asynchronous mode + BGR04 = 416; // 38400 Baud @ 16MHz + SCR04 = 0x17; // 8N1 + SMR04 = 0x0d; // enable SOT3, Reset, normal mode + SSR04 = 0x00; // LSB first + PFR19 = (PFR19 & 0xFC) | 0x03; // enable UART: SIN,SOT for async. transfer + EPFR19 = 0x00; // enable UART } -void Putch4(char ch) /* sends a char */ +void Putch4(unsigned char ch) /* sends a char */ { - while (SSR04_TDRE == 0); /* wait for transmit buffer empty */ - TDR04 = ch; /* put ch into buffer */ + while (SSR04_TDRE == 0); /* wait for transmit buffer empty */ + TDR04 = ch; /* put ch into buffer */ } -char Getch4(void) /* waits for and returns incomming char */ +unsigned char Getch4(void) /* waits for and returns incomming char */ { - volatile unsigned ch; - - for(;;) - { - - while(SSR04_RDRF == 0) /* wait for data received */ - HWWD = 0x00; - - ch = RDR04; - - if ((SSR04 & 0xE0) != 0) /* Check for errors PE, ORE, FRE */ - { - SCR04_CRE = 1; /* Clear error flags */ - } - else - return (ch); /* return char */ - } + volatile unsigned ch; + for(;;) { + while(SSR04_RDRF == 0) /* wait for data received */ + HWWD = 0x00; + ch = RDR04; + + if ((SSR04 & 0xE0) != 0) { /* Check for errors PE, ORE, FRE */ + SCR04_CRE = 1; /* Clear error flags */ + } else { + return (ch); /* return char*/ + } + } } -void Puts4(const char *Name2) /* Puts a String to UART */ +void Puts4(const char *Name2) { - volatile int i,len; - - len = strlen(Name2); + volatile int i,len; + len = strlen(Name2); - for (i=0; i> div)&0xF); /* get hex-digit value */ - Putch4(digit + ((digit < 0xA) ? '0' : 'A' - 0xA)); - div-=4; /* next digit shift */ - } + div=(4*(digits-1)); /* init shift divisor */ + for (i=0;i> div)&0xF); /* get hex-digit value */ + Putch4(digit + ((digit < 0xA) ? '0' : 'A' - 0xA)); + div-=4; /* next digit shift */ + } } void Putdec4(unsigned long x, int digits) @@ -104,26 +68,22 @@ void Putdec4(unsigned long x, int digits) char buf[10],sign=1; if (digits < 0) { /* should be print of zero? */ - digits *= (-1); - sign =1; + digits *= (-1); + sign =1; } buf[digits]='\0'; /* end sign of string */ for (i=digits; i>0; i--) { - buf[i-1] = ASCII[x % 10]; + buf[i-1] = ASCII[x % 10]; // + '0' enough? :o x = x/10; } - if ( sign ) - { - for (i=0; buf[i]=='0'; i++) { /* no print of zero */ - if ( i