1*1664436fSMatthias Ringwald /** 2*1664436fSMatthias Ringwald * @file hal_usb.c 3*1664436fSMatthias Ringwald * 4*1664436fSMatthias Ringwald * Copyright 2008 Texas Instruments, Inc. 5*1664436fSMatthias Ringwald ***************************************************************************/ 6*1664436fSMatthias Ringwald #include <msp430x54x.h> 7*1664436fSMatthias Ringwald #include "hal_usb.h" 8*1664436fSMatthias Ringwald 9*1664436fSMatthias Ringwald 10*1664436fSMatthias Ringwald #ifdef USE_IRQ_RX 11*1664436fSMatthias Ringwald static char halUsbReceiveBuffer[255]; 12*1664436fSMatthias Ringwald static unsigned char bufferSize=0; 13*1664436fSMatthias Ringwald #endif 14*1664436fSMatthias Ringwald 15*1664436fSMatthias Ringwald /************************************************************************ 16*1664436fSMatthias Ringwald * @brief Initializes the serial communications peripheral and GPIO ports 17*1664436fSMatthias Ringwald * to communicate with the TUSB3410. 18*1664436fSMatthias Ringwald * 19*1664436fSMatthias Ringwald * @param none 20*1664436fSMatthias Ringwald * 21*1664436fSMatthias Ringwald * @return none 22*1664436fSMatthias Ringwald **************************************************************************/ halUsbInit(void)23*1664436fSMatthias Ringwaldvoid halUsbInit(void) 24*1664436fSMatthias Ringwald { 25*1664436fSMatthias Ringwald 26*1664436fSMatthias Ringwald #ifdef USE_IRQ_RX 27*1664436fSMatthias Ringwald volatile unsigned char i; 28*1664436fSMatthias Ringwald for (i = 0;i < 255; i++){ 29*1664436fSMatthias Ringwald halUsbReceiveBuffer[i]='\0'; 30*1664436fSMatthias Ringwald } 31*1664436fSMatthias Ringwald bufferSize = 0; 32*1664436fSMatthias Ringwald #endif 33*1664436fSMatthias Ringwald 34*1664436fSMatthias Ringwald USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD; 35*1664436fSMatthias Ringwald USB_PORT_DIR |= USB_PIN_TXD; 36*1664436fSMatthias Ringwald USB_PORT_DIR &= ~USB_PIN_RXD; 37*1664436fSMatthias Ringwald 38*1664436fSMatthias Ringwald UCA3CTL1 |= UCSWRST; //Reset State 39*1664436fSMatthias Ringwald UCA3CTL0 = UCMODE_0; 40*1664436fSMatthias Ringwald 41*1664436fSMatthias Ringwald UCA3CTL0 &= ~UC7BIT; // 8bit char 42*1664436fSMatthias Ringwald UCA3CTL1 |= UCSSEL_2; 43*1664436fSMatthias Ringwald 44*1664436fSMatthias Ringwald // 115200 on 16 Mhz 45*1664436fSMatthias Ringwald // UCA3BR0 = 16; // 8Mhz/57600=138 46*1664436fSMatthias Ringwald // UCA3BR1 = 1; 47*1664436fSMatthias Ringwald // UCA3MCTL = 0xE; 48*1664436fSMatthias Ringwald 49*1664436fSMatthias Ringwald // 9600 on 16 Mhz - from family user guide 50*1664436fSMatthias Ringwald UCA3BR1 = 0x06; 51*1664436fSMatthias Ringwald UCA3BR0 = 0x82; 52*1664436fSMatthias Ringwald UCA3MCTL = 0xC; 53*1664436fSMatthias Ringwald 54*1664436fSMatthias Ringwald UCA3CTL1 &= ~UCSWRST; 55*1664436fSMatthias Ringwald // UCA3IE |= UCRXIE; 56*1664436fSMatthias Ringwald // __bis_SR_register(GIE); // Enable Interrupts 57*1664436fSMatthias Ringwald } 58*1664436fSMatthias Ringwald 59*1664436fSMatthias Ringwald /************************************************************************ 60*1664436fSMatthias Ringwald * @brief Disables the serial communications peripheral and clears the GPIO 61*1664436fSMatthias Ringwald * settings used to communicate with the TUSB3410. 62*1664436fSMatthias Ringwald * 63*1664436fSMatthias Ringwald * @param none 64*1664436fSMatthias Ringwald * 65*1664436fSMatthias Ringwald * @return none 66*1664436fSMatthias Ringwald **************************************************************************/ halUsbShutDown(void)67*1664436fSMatthias Ringwaldvoid halUsbShutDown(void) 68*1664436fSMatthias Ringwald { 69*1664436fSMatthias Ringwald UCA3IE &= ~UCRXIE; 70*1664436fSMatthias Ringwald UCA3CTL1 = UCSWRST; //Reset State 71*1664436fSMatthias Ringwald USB_PORT_SEL &= ~( USB_PIN_RXD + USB_PIN_TXD ); 72*1664436fSMatthias Ringwald USB_PORT_DIR |= USB_PIN_TXD; 73*1664436fSMatthias Ringwald USB_PORT_DIR |= USB_PIN_RXD; 74*1664436fSMatthias Ringwald USB_PORT_OUT &= ~(USB_PIN_TXD + USB_PIN_RXD); 75*1664436fSMatthias Ringwald } 76*1664436fSMatthias Ringwald 77*1664436fSMatthias Ringwald /************************************************************************ 78*1664436fSMatthias Ringwald * @brief Sends a character over UART to the TUSB3410. 79*1664436fSMatthias Ringwald * 80*1664436fSMatthias Ringwald * @param character The character to be sent. 81*1664436fSMatthias Ringwald * 82*1664436fSMatthias Ringwald * @return none 83*1664436fSMatthias Ringwald **************************************************************************/ halUsbSendChar(char character)84*1664436fSMatthias Ringwaldvoid halUsbSendChar(char character) 85*1664436fSMatthias Ringwald { 86*1664436fSMatthias Ringwald while (!(UCA3IFG & UCTXIFG)); 87*1664436fSMatthias Ringwald UCA3TXBUF = character; 88*1664436fSMatthias Ringwald } 89*1664436fSMatthias Ringwald halUsbRecvChar(void)90*1664436fSMatthias Ringwaldchar halUsbRecvChar(void){ 91*1664436fSMatthias Ringwald while (!(UCA3IFG & UCRXIFG)); 92*1664436fSMatthias Ringwald return UCA3RXBUF; 93*1664436fSMatthias Ringwald } 94*1664436fSMatthias Ringwald 95*1664436fSMatthias Ringwald /************************************************************************ 96*1664436fSMatthias Ringwald * @brief Sends a string of characters to the TUSB3410 97*1664436fSMatthias Ringwald * 98*1664436fSMatthias Ringwald * @param string[] The array of characters to be transmit to the TUSB3410. 99*1664436fSMatthias Ringwald * 100*1664436fSMatthias Ringwald * @param length The length of the string. 101*1664436fSMatthias Ringwald * 102*1664436fSMatthias Ringwald * @return none 103*1664436fSMatthias Ringwald **************************************************************************/ halUsbSendString(char string[],unsigned char length)104*1664436fSMatthias Ringwaldvoid halUsbSendString(char string[], unsigned char length) 105*1664436fSMatthias Ringwald { 106*1664436fSMatthias Ringwald volatile unsigned char i; 107*1664436fSMatthias Ringwald for (i=0; i < length; i++) 108*1664436fSMatthias Ringwald halUsbSendChar(string[i]); 109*1664436fSMatthias Ringwald } 110*1664436fSMatthias Ringwald 111*1664436fSMatthias Ringwald #ifdef USE_IRQ_RX 112*1664436fSMatthias Ringwald /************************************************************************/ USCI_A1_ISR(void)113*1664436fSMatthias Ringwaldinterrupt(USCI_A1_VECTOR) USCI_A1_ISR (void) 114*1664436fSMatthias Ringwald { 115*1664436fSMatthias Ringwald halUsbReceiveBuffer[bufferSize++] = UCA3RXBUF; 116*1664436fSMatthias Ringwald __bic_SR_register_on_exit(LPM3_bits); 117*1664436fSMatthias Ringwald } 118*1664436fSMatthias Ringwald #endif 119*1664436fSMatthias Ringwald 120*1664436fSMatthias Ringwald // provide putchar used by printf putchar(int c)121*1664436fSMatthias Ringwaldint putchar(int c){ 122*1664436fSMatthias Ringwald halUsbSendChar(c); 123*1664436fSMatthias Ringwald return 1; 124*1664436fSMatthias Ringwald }