#!/bin/sh -x # usage: xen-clone hg_repository dest_dir orig_linux_dir # # this script contains some CL site specific details, but can easily be adapted # # test which site we're on [ -d /usr/groups/xeno/ -a -d /usr/groups/srgboot ] && SITE=UCCL case "$SITE" in UCCL) BK_REP=${1:-http://hg.srg.cl.cam.ac.uk/xen-unstable.hg} LINUX_DIR=${3:-/usr/groups/xeno/archive/} ;; *) BK_REP=${1:-http://xenbits.xensource.com/xen-unstable.hg} LINUX_DIR=${3:-.:..} ;; esac DEST_DIR=${2:-xeno-clone} DEST_BK_REP=`basename "${BK_REP}"` DEST_VER=`basename ${DEST_BK_REP} .hg` echo usage: xen-clone hg dest_dir orig_linux_dir echo Source BK Repository : ${BK_REP} echo Destination Dir/Repository : ${DEST_DIR}/${DEST_BK_REP} echo Pristine Linux Source directory : ${LINUX_DIR} mkdir -p ${DEST_DIR} cd ${DEST_DIR} TOP=`/bin/pwd` # site-specific set up of installation directories case "$SITE" in UCCL) PATH=$PATH:/usr/groups/xeno/build_tools/bin mkdir -p install/boot cd install/boot ln -sf ../../../xeno-roots/roots . ln -sf ../../../xeno-roots/usr . ln -sf ../lib . ln -sf ../bin . ln -sf /usr/groups/srgboot/${USER}/xenoboot.sh . ln -sf `pwd` /usr/groups/srgboot/${USER}/${DEST_DIR} ln -sf xen.gz image.gz cd ../.. ;; esac # clone the master repository (now checked-out by default) if [ ! -d ${DEST_BK_REP} ] then mkdir -p ${DEST_BK_REP} ; cd ${DEST_BK_REP} ; hg init ${BK_REP} ; hg co ; cd ${TOP} else cd ${DEST_BK_REP} hg pull ; hg co cd ${TOP} fi if [ -d ${DEST_BK_REP}/linux-2.4*-xen-sparse ] then # this is a new style Xen repository so building is dead easy export LINUX_SRC_PATH=${LINUX_DIR} cd ${DEST_BK_REP} # Recent repositories install into 'dist/install' rather than 'install'. if [ -f install.sh ] then mkdir -p dist ln -sf ../../install dist/install else ln -sf ../install install fi make -j4 KERNELS=linux-* world #make -j4 linux24 cd ../install/boot if [ -r vmlinuz-2.6-xen0 ] then ln -s vmlinuz-2.6-xen0 xenolinux.gz else kern=`ls vmlinuz-2.6.*-xen0 | head -1` [ -r "$kern" ] && ln -s "$kern" xenolinux.gz fi else # old style repository without 'make world' # identify this version of linux LINUX_VER=`( /bin/ls -ld ${DEST_BK_REP}/*xenolinux-sparse || /bin/ls -ld ${DEST_BK_REP}/*xenolinux-*-sparse ) 2>/dev/null | sed -e 's!^.*xenolinux-\(.\+\)-sparse!\1!'` if [ -z "${LINUX_VER}" ] then echo Unable to identify Linux version. Bailing. exit -1 fi # copy in the master Linux tree for this kernel if [ ! -d linux-${LINUX_VER} ] then tar -jxf ${LINUX_DIR}/linux-${LINUX_VER}.tar.bz2 || tar -zxf ${LINUX_DIR}/linux-${LINUX_VER}.tar.gz || tar -zxf ${LINUX_DIR}/linux-${LINUX_VER}.tgz || cp -a ${LINUX_DIR}/linux-${LINUX_VER} . || wget ftp://ftp.kernel.org/pub/linux/kernel/v2.4/linux-${LINUX_VER}.tar.gz -O- | tar -zxf - || exit -1 fi # build and install Xen and tools cd ${DEST_BK_REP} make dist || make install # Turn linux into xenolinux then build it cd xenolinux-${LINUX_VER}-sparse bash ./mkbuildtree ../../linux-${LINUX_VER} cd ../.. mv linux-${LINUX_VER} xenolinux-${LINUX_VER} cd xenolinux-${LINUX_VER} # cope with the change from ARCH=xeno to ARCH=xen cd arch; XEN=`/bin/ls -d xen*`; cd .. # built it all ARCH=$XEN make oldconfig ARCH=$XEN make dep ARCH=$XEN make bzImage ARCH=$XEN make dist || ARCH=xen make install ARCH=$XEN make modules ARCH=$XEN make INSTALL_MOD_PATH=${TOP}/install modules_install cd .. fi id='n12' href='#n12'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
// TODO: Teensy support(ATMega32u4/AT90USB128)
// Fixed for Arduino Duemilanove ATmega168p by Jun Wako
/* UART Example for Teensy USB Development Board
* http://www.pjrc.com/teensy/
* Copyright (c) 2009 PJRC.COM, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Version 1.0: Initial Release
// Version 1.1: Add support for Teensy 2.0, minor optimizations
#include <avr/io.h>
#include <avr/interrupt.h>
#include "uart.h"
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
# define UDRn UDR0
# define UBRRnL UBRR0L
# define UCSRnA UCSR0A
# define UCSRnB UCSR0B
# define UCSRnC UCSR0C
# define U2Xn U2X0
# define RXENn RXEN0
# define TXENn TXEN0
# define RXCIEn RXCIE0
# define UCSZn1 UCSZ01
# define UCSZn0 UCSZ00
# define UDRIEn UDRIE0
# define USARTn_UDRE_vect USART_UDRE_vect
# define USARTn_RX_vect USART_RX_vect
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
# define UDRn UDR1
# define UBRRnL UBRR1L
# define UCSRnA UCSR1A
# define UCSRnB UCSR1B
# define UCSRnC UCSR1C
# define U2Xn U2X1
# define RXENn RXEN1
# define TXENn TXEN1
# define RXCIEn RXCIE1
# define UCSZn1 UCSZ11
# define UCSZn0 UCSZ10
# define UDRIEn UDRIE1
# define USARTn_UDRE_vect USART1_UDRE_vect
# define USARTn_RX_vect USART1_RX_vect
#elif defined(__AVR_ATmega32A__)
# define UDRn UDR
# define UBRRnL UBRRL
# define UCSRnA UCSRA
# define UCSRnB UCSRB
# define UCSRnC UCSRC
# define U2Xn U2X
# define RXENn RXEN
# define TXENn TXEN
# define RXCIEn RXCIE
# define UCSZn1 UCSZ1
# define UCSZn0 UCSZ0
# define UDRIEn UDRIE
# define USARTn_UDRE_vect USART_UDRE_vect
# define USARTn_RX_vect USART_RX_vect
#endif
// These buffers may be any size from 2 to 256 bytes.
#define RX_BUFFER_SIZE 64
#define TX_BUFFER_SIZE 256
static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
static volatile uint8_t tx_buffer_head;
static volatile uint8_t tx_buffer_tail;
static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
static volatile uint8_t rx_buffer_head;
static volatile uint8_t rx_buffer_tail;
// Initialize the UART
void uart_init(uint32_t baud) {
cli();
UBRRnL = (F_CPU / 4 / baud - 1) / 2;
UCSRnA = (1 << U2Xn);
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
tx_buffer_head = tx_buffer_tail = 0;
rx_buffer_head = rx_buffer_tail = 0;
sei();
}
// Transmit a byte
void uart_putchar(uint8_t c) {
uint8_t i;
i = tx_buffer_head + 1;
if (i >= TX_BUFFER_SIZE) i = 0;
// return immediately to avoid deadlock when interrupt is disabled(called from ISR)
if (tx_buffer_tail == i && (SREG & (1 << SREG_I)) == 0) return;
while (tx_buffer_tail == i)
; // wait until space in buffer
// cli();
tx_buffer[i] = c;
tx_buffer_head = i;
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
// sei();
}
// Receive a byte
uint8_t uart_getchar(void) {
uint8_t c, i;
while (rx_buffer_head == rx_buffer_tail)
; // wait for character
i = rx_buffer_tail + 1;
if (i >= RX_BUFFER_SIZE) i = 0;
c = rx_buffer[i];
rx_buffer_tail = i;
return c;
}
// Return the number of bytes waiting in the receive buffer.
// Call this before uart_getchar() to check if it will need
// to wait for a byte to arrive.
uint8_t uart_available(void) {
uint8_t head, tail;
head = rx_buffer_head;
tail = rx_buffer_tail;
if (head >= tail) return head - tail;
return RX_BUFFER_SIZE + head - tail;
}
// Transmit Interrupt
ISR(USARTn_UDRE_vect) {
uint8_t i;
if (tx_buffer_head == tx_buffer_tail) {
// buffer is empty, disable transmit interrupt
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
} else {
i = tx_buffer_tail + 1;
if (i >= TX_BUFFER_SIZE) i = 0;
UDRn = tx_buffer[i];
tx_buffer_tail = i;
}
}
// Receive Interrupt
ISR(USARTn_RX_vect) {
uint8_t c, i;
c = UDRn;
i = rx_buffer_head + 1;
if (i >= RX_BUFFER_SIZE) i = 0;
if (i != rx_buffer_tail) {
rx_buffer[i] = c;
rx_buffer_head = i;
}
}