freemyipod r687 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r686‎ | r687 | r688 >
Date:22:47, 30 March 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix red (commit missing files)
Modified paths:
  • /emcore/trunk/target/ipodnano3g/uart.c (added) (history)
  • /emcore/trunk/uart.h (added) (history)

Diff [purge]

Index: emcore/trunk/target/ipodnano3g/uart.c
@@ -0,0 +1,86 @@
 2+//
 3+//
 4+// Copyright 2011 TheSeven
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#include "global.h"
 26+#include "uart.h"
 27+#include "s5l8702.h"
 28+#include "timer.h"
 29+
 30+
 31+void uart_init()
 32+{
 33+ clockgate_enable(41, true);
 34+ ULCON = 3;
 35+ UCON = 0x405;
 36+ UFCON = 7;
 37+ UMCON = 0;
 38+ uart_set_baud(250000);
 39+}
 40+
 41+void uart_set_baud(int baud)
 42+{
 43+ UBRDIV = (750000 / baud) - 1;
 44+}
 45+
 46+void uart_putc(char byte)
 47+{
 48+ while (UFSTAT & BIT(9)) sleep(100);
 49+ UTXH = byte;
 50+}
 51+
 52+void uart_puts(const char* string)
 53+{
 54+ char byte;
 55+ while (byte = *string++) uart_putc(byte);
 56+}
 57+
 58+void uart_write(const char* string, size_t length)
 59+{
 60+ while (length--) uart_putc(*string++);
 61+}
 62+
 63+int uart_getc(int timeout)
 64+{
 65+ int byte = -1;
 66+ long starttime = USEC_TIMER;
 67+ while (!(UFSTAT & BITRANGE(0, 3)) && !TIMEOUT_EXPIRED(starttime, timeout)) sleep(100);
 68+ if (UFSTAT & BITRANGE(0, 3)) byte = URXH;
 69+ return byte;
 70+}
 71+
 72+int uart_read(char* string, size_t length, int timeout)
 73+{
 74+ int count = 0;
 75+ long starttime = USEC_TIMER;
 76+ while (length && !TIMEOUT_EXPIRED(starttime, timeout))
 77+ {
 78+ if (UFSTAT & BITRANGE(0, 3))
 79+ {
 80+ *string++ = URXH;
 81+ length--;
 82+ count++;
 83+ }
 84+ else sleep(100);
 85+ }
 86+ return count;
 87+}
Index: emcore/trunk/uart.h
@@ -0,0 +1,40 @@
 2+//
 3+//
 4+// Copyright 2011 TheSeven
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __UART_H__
 26+#define __UART_H__
 27+
 28+
 29+#include "global.h"
 30+
 31+
 32+void uart_init() INITCODE_ATTR;
 33+void uart_set_baud(int baud);
 34+void uart_putc(char string) ICODE_ATTR;
 35+void uart_puts(const char* string) ICODE_ATTR;
 36+void uart_write(const char* string, size_t length) ICODE_ATTR;
 37+int uart_getc(int timeout) ICODE_ATTR;
 38+int uart_read(char* string, size_t length, int timeout) ICODE_ATTR;
 39+
 40+
 41+#endif