Changeset 1463


Ignore:
Timestamp:
02/25/12 21:26:00 (15 months ago)
Author:
thomas
Message:
  • renaming all callback declaration as *_cbt
  • enable GIE at end of board_init()
  • UART bsp module with callback functionality
  • UART module at 9600 baud
  • UART bsp demo project which prints "Hello World!"
Location:
trunk/firmware/openos
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/firmware/openos/bsp/spi.h

    r1455 r1463  
    4343} spi_last_t; 
    4444 
    45 typedef void (*spiCallback_t)(void); 
     45typedef void (*spi_cbt)(void); 
    4646 
    4747//=========================== variables ======================================= 
     
    5151void    spi_init(); 
    5252#ifdef SPI_IN_RTOS_MODE 
    53 void    spi_setCallback(spiCallback_t cb); 
     53void    spi_setCallback(spi_cbt cb); 
    5454#endif 
    5555void    spi_txrx(uint8_t*     bufTx, 
  • trunk/firmware/openos/bsp/telosb/board.c

    r1457 r1463  
    3131   leds_init(); 
    3232   uart_init(); 
    33    spi_init(); 
    34    radio_init(); 
    35    radiotimer_init(); 
     33   //spi_init(); 
     34   //radio_init(); 
     35   //radiotimer_init(); 
     36    
     37   __bis_SR_register(GIE); 
    3638} 
    3739 
  • trunk/firmware/openos/bsp/telosb/spi.c

    r1462 r1463  
    2929#ifdef SPI_IN_RTOS_MODE 
    3030   // callback when module done 
    31    spiCallback_t   callback; 
     31   spi_cbt         callback; 
    3232#endif 
    3333} spi_vars_t; 
     
    102102 
    103103#ifdef SPI_IN_RTOS_MODE 
    104 void spi_setCallback(spiCallback_t cb) { 
     104void spi_setCallback(spi_cbt cb) { 
    105105   spi_vars.callback = cb; 
    106106} 
  • trunk/firmware/openos/bsp/telosb/uart.c

    r1415 r1463  
    77#include "msp430f1611.h" 
    88#include "stdint.h" 
     9#include "stdio.h" 
    910#include "uart.h" 
    1011 
    1112//=========================== defines ========================================= 
    1213 
    13 #define BAUDRATE_115200 
    14  
    1514//=========================== variables ======================================= 
    1615 
    1716typedef struct { 
    18    uint8_t callBack; 
     17   // TX 
     18   uint8_t*   txBuf; 
     19   uint8_t    txBufLen; 
     20   uart_cbt   txDone_cb; 
     21   // RX 
     22   uint8_t*   rxBuffer; 
     23   uint8_t    rxBytesReceived; 
     24   uint8_t    rxBytesTreshold; 
     25   uart_cbt   rxThreshold_cb; 
    1926} uart_vars_t; 
    2027 
     
    2835   P3SEL      =  0xC0;                           // P3.6,7 = UART1TX/RX 
    2936    
    30    ME2       |=  UTXE1 + URXE1;                  // enable UART1 TX/RX 
     37   UCTL1      =  SWRST;                          // hold UART1 module in reset 
    3138   UCTL1     |=  CHAR;                           // 8-bit character 
    3239    
    33 #ifdef BAUDRATE_115200 
     40#ifdef UART_BAUDRATE_115200 
    3441   //115200 baud, clocked from 4.8MHz SMCLK 
    3542   UTCTL1    |=  SSEL1;                          // clocking from SMCLK 
     
    4552#endif 
    4653    
     54   ME2       |=  UTXE1 + URXE1;                  // enable UART1 TX/RX 
    4755   UCTL1     &= ~SWRST;                          // clear UART1 reset bit 
    48    //IE2       |=  URXIE1;                         // enable UART1 RX interrupt 
     56   IE2       |=  UTXIE1 + URXIE1;                // enable UART1 TX/RX interrupt 
    4957} 
    5058 
    51 void uart_tx(uint8_t c) { 
    52    U1TXBUF    = c; 
     59void uart_setTxDoneCb(uart_cbt cb) { 
     60   uart_vars.txDone_cb       = cb; 
     61} 
     62 
     63void uart_setRxThresholdCb(uart_cbt cb) { 
     64   uart_vars.rxThreshold_cb  = cb; 
     65} 
     66 
     67void uart_tx(uint8_t* txBuf, uint8_t txBufLen) { 
     68    
     69   // register data to send 
     70   uart_vars.txBuf           = txBuf; 
     71   uart_vars.txBufLen        = txBufLen; 
     72    
     73   // send first byte 
     74   U1TXBUF                   = *uart_vars.txBuf; 
    5375} 
    5476 
    5577//=========================== private ========================================= 
     78 
     79//=========================== interrupt handlers ============================== 
     80 
     81#pragma vector = USART1TX_VECTOR 
     82__interrupt void usart1tx_VECTOR (void) { 
     83   // one byte less to go 
     84   uart_vars.txBufLen--; 
     85   uart_vars.txBuf++; 
     86    
     87   if (uart_vars.txBufLen>0) { 
     88      // send next byte 
     89      U1TXBUF                   = *uart_vars.txBuf; 
     90   } else { 
     91      if (uart_vars.txDone_cb!=NULL) { 
     92         uart_vars.txDone_cb(); 
     93      } 
     94   } 
     95} 
     96 
     97#pragma vector = USART1RX_VECTOR 
     98__interrupt void usart1rx_VECTOR (void) { 
     99   P5OUT    ^=  0x10;                           // toggle LED 
     100} 
  • trunk/firmware/openos/bsp/uart.h

    r1415 r1463  
    1212//=========================== define ========================================== 
    1313 
     14//#define UART_BAUDRATE_115200 
     15 
    1416//=========================== typedef ========================================= 
     17 
     18typedef void (*uart_cbt)(void); 
    1519 
    1620//=========================== variables ======================================= 
     
    1923 
    2024void uart_init(); 
    21 void uart_tx(uint8_t c); 
     25void uart_setTxDoneCb(uart_cbt cb); 
     26void uart_setRxThresholdCb(uart_cbt cb); 
     27void uart_tx(uint8_t* txBuf, uint8_t txBufLen); 
    2228 
    2329#endif 
  • trunk/firmware/openos/projects/telosb/01-bsp/01bsp_radio.c

    r1461 r1463  
    1818//=========================== variables ======================================= 
    1919 
    20 void cb_radioTimerOverflows(); 
    21 void cb_radioTimerCompare(); 
    22 void cb_startFrame(uint16_t timestamp); 
    23 void cb_endFrame(uint16_t timestamp); 
    24  
    2520typedef struct { 
    2621   uint8_t radio_busy; 
     
    3227 
    3328app_vars_t app_vars; 
     29 
     30//=========================== prototypes ====================================== 
     31 
     32void cb_radioTimerOverflows(); 
     33void cb_radioTimerCompare(); 
     34void cb_startFrame(uint16_t timestamp); 
     35void cb_endFrame(uint16_t timestamp); 
    3436 
    3537//=========================== main ============================================ 
  • trunk/firmware/openos/projects/telosb/01-bsp/01bsp_uart.c

    r1421 r1463  
    1010#include "uart.h" 
    1111 
     12//=========================== defines ========================================= 
     13 
     14uint8_t stringToSend[] = "Hello World!"; 
     15 
     16//=========================== variables ======================================= 
     17 
     18typedef struct { 
     19   uint8_t uart_busy; 
     20} app_vars_t; 
     21 
     22app_vars_t app_vars; 
     23 
     24//=========================== prototypes ====================================== 
     25 
     26void cb_uartDone(); 
     27 
     28//=========================== main ============================================ 
     29 
    1230/** 
    1331\brief The program starts executing here. 
     
    1735   board_init(); 
    1836    
    19    while (1) { 
    20       uart_tx('a'); 
     37   uart_setTxDoneCb(cb_uartDone); 
     38    
     39   uart_tx(&stringToSend[0],sizeof(stringToSend)); 
     40    
     41   app_vars.uart_busy = 1; 
     42   while (app_vars.uart_busy==1) { 
    2143   } 
     44    
     45   // go back to sleep 
     46   board_sleep(); 
    2247} 
     48 
     49//=========================== callbacks ======================================= 
     50 
     51void cb_uartDone() { 
     52   app_vars.uart_busy = 0; 
     53} 
Note: See TracChangeset for help on using the changeset viewer.