1 /** 2 * @file hal_usb.c 3 * 4 * Copyright 2008 Texas Instruments, Inc. 5 ***************************************************************************/ 6 #include <msp430.h> 7 #include "hal_usb.h" 8 9 /************************************************************************ 10 * @brief Initializes the serial communications peripheral and GPIO ports 11 * to communicate with the TUSB3410. 12 * 13 * @param none 14 * 15 * @return none 16 **************************************************************************/ halUsbInit(void)17void halUsbInit(void) 18 { 19 20 USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD; 21 USB_PORT_DIR |= USB_PIN_TXD; 22 USB_PORT_DIR &= ~USB_PIN_RXD; 23 24 UCA1CTL1 |= UCSWRST; //Reset State 25 UCA1CTL0 = UCMODE_0; 26 27 UCA1CTL0 &= ~UC7BIT; // 8bit char 28 UCA1CTL1 |= UCSSEL_2; 29 #if 0 30 // 57600 @ 16 Mhz 31 UCA1BR0 = 16; 32 UCA1BR1 = 1; 33 #else 34 // 115200 @ 16 Mhz 35 UCA1BR0 = 138; 36 UCA1BR1 = 0; 37 #endif 38 UCA1MCTL = 0xE; 39 UCA1CTL1 &= ~UCSWRST; 40 } 41 42 /************************************************************************ 43 * @brief Disables the serial communications peripheral and clears the GPIO 44 * settings used to communicate with the TUSB3410. 45 * 46 * @param none 47 * 48 * @return none 49 **************************************************************************/ halUsbShutDown(void)50void halUsbShutDown(void) 51 { 52 UCA1IE &= ~UCRXIE; 53 UCA1CTL1 = UCSWRST; //Reset State 54 USB_PORT_SEL &= ~( USB_PIN_RXD + USB_PIN_TXD ); 55 USB_PORT_DIR |= USB_PIN_TXD; 56 USB_PORT_DIR |= USB_PIN_RXD; 57 USB_PORT_OUT &= ~(USB_PIN_TXD + USB_PIN_RXD); 58 } 59 60 /************************************************************************ 61 * @brief Sends a character over UART to the TUSB3410. 62 * 63 * @param character The character to be sent. 64 * 65 * @return none 66 **************************************************************************/ halUsbSendChar(char character)67void halUsbSendChar(char character) 68 { 69 while (!(UCA1IFG & UCTXIFG)); 70 UCA1TXBUF = character; 71 } 72 halUsbRecvChar(void)73char halUsbRecvChar(void){ 74 while (!(UCA1IFG & UCRXIFG)); 75 return UCA1RXBUF; 76 } 77 78 /************************************************************************ 79 * @brief Sends a string of characters to the TUSB3410 80 * 81 * @param string[] The array of characters to be transmit to the TUSB3410. 82 * 83 * @param length The length of the string. 84 * 85 * @return none 86 **************************************************************************/ halUsbSendString(char string[],unsigned char length)87void halUsbSendString(char string[], unsigned char length) 88 { 89 volatile unsigned char i; 90 for (i=0; i < length; i++) 91 halUsbSendChar(string[i]); 92 } 93 94 // provide putchar used by printf putchar(int c)95int putchar(int c){ 96 halUsbSendChar(c); 97 return 1; 98 }