Changeset 1459


Ignore:
Timestamp:
02/25/12 18:57:16 (15 months ago)
Author:
thomas
Message:

use callback functions in radio drivers (fully interrupt-driven)

Location:
trunk/firmware/openos
Files:
5 edited

Legend:

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

    r1457 r1459  
    77#ifndef __RADIO_H 
    88#define __RADIO_H 
     9 
     10#include "radiotimer.h" 
    911 
    1012//=========================== define ========================================== 
     
    1921void radio_reset(); 
    2022void radio_startTimer(uint16_t period); 
     23void radio_setOverflowCb(radiotimer_compare_cbt cb); 
     24void radio_setCompareCb(radiotimer_compare_cbt cb); 
     25void radio_setStartFrameCb(radiotimer_capture_cbt cb); 
     26void radio_setEndFrameCb(radiotimer_capture_cbt cb); 
    2127void radio_setFrequency(uint8_t frequency); 
    2228void radio_rfOn(); 
  • trunk/firmware/openos/bsp/radiotimer.h

    r1457 r1459  
    1414//=========================== typedef ========================================= 
    1515 
    16 typedef void (*radiotimer_overflow_cbt)(); 
    17 typedef void (*radiotimer_frame_cbt)(uint16_t timestamp); 
     16typedef void (*radiotimer_compare_cbt)(); 
     17typedef void (*radiotimer_capture_cbt)(uint16_t timestamp); 
    1818 
    1919//=========================== variables ======================================= 
     
    2222 
    2323void     radiotimer_init(); 
     24void     radiotimer_setOverflowCb(radiotimer_compare_cbt cb); 
     25void     radiotimer_setCompareCb(radiotimer_compare_cbt cb); 
     26void     radiotimer_setStartFrameCb(radiotimer_capture_cbt cb); 
     27void     radiotimer_setEndFrameCb(radiotimer_capture_cbt cb); 
    2428void     radiotimer_start(uint16_t period);  
    2529void     radiotimer_schedule(uint16_t offset); 
  • trunk/firmware/openos/bsp/telosb/radio.c

    r1457 r1459  
    5050void radio_startTimer(uint16_t period) { 
    5151   radiotimer_start(period); 
     52} 
     53 
     54void radio_setOverflowCb(radiotimer_compare_cbt cb) { 
     55   radiotimer_setOverflowCb(cb); 
     56} 
     57 
     58void radio_setCompareCb(radiotimer_compare_cbt cb) { 
     59   radiotimer_setCompareCb(cb); 
     60} 
     61 
     62void radio_setStartFrameCb(radiotimer_capture_cbt cb) { 
     63   radiotimer_setStartFrameCb(cb); 
     64} 
     65 
     66void radio_setEndFrameCb(radiotimer_capture_cbt cb) { 
     67   radiotimer_setEndFrameCb(cb); 
    5268} 
    5369 
  • trunk/firmware/openos/bsp/telosb/radiotimer.c

    r1457 r1459  
    1313 
    1414typedef struct { 
    15    radiotimer_overflow_cbt   overflowCb; 
    16    radiotimer_frame_cbt      startOfFrameCb; 
    17    radiotimer_frame_cbt      endOfFrameCb; 
     15   radiotimer_compare_cbt    overflowCb; 
     16   radiotimer_compare_cbt    compareCb; 
     17   radiotimer_capture_cbt    startFrameCb; 
     18   radiotimer_capture_cbt    endFrameCb; 
    1819} radiotimer_vars_t; 
    1920 
     
    2930} 
    3031 
    31 void radiotimer_setOverflowCb(radiotimer_overflow_cbt cb) { 
    32    radiotimer_vars.overflowCb = cb; 
     32void radiotimer_setOverflowCb(radiotimer_compare_cbt cb) { 
     33   radiotimer_vars.overflowCb     = cb; 
    3334} 
    3435 
    35 void radiotimer_setStartOfFrameCb(radiotimer_frame_cbt cb) { 
    36    radiotimer_vars.startOfFrameCb = cb; 
     36void radiotimer_setCompareCb(radiotimer_compare_cbt cb) { 
     37   radiotimer_vars.compareCb      = cb; 
    3738} 
    3839 
    39 void radiotimer_setEndOfFrameCb(radiotimer_frame_cbt cb) { 
    40    radiotimer_vars.endOfFrameCb   = cb; 
     40void radiotimer_setStartFrameCb(radiotimer_capture_cbt cb) { 
     41   radiotimer_vars.startFrameCb = cb; 
     42} 
     43 
     44void radiotimer_setEndFrameCb(radiotimer_capture_cbt cb) { 
     45   radiotimer_vars.endFrameCb   = cb; 
    4146} 
    4247 
     
    105110         if (TBCCR1 & CCI) { 
    106111            // SFD pin is high: this was the start of a frame 
    107             if (radiotimer_vars.startOfFrameCb!=NULL) { 
    108                radiotimer_vars.startOfFrameCb(TBCCR1); 
     112            if (radiotimer_vars.startFrameCb!=NULL) { 
     113               radiotimer_vars.startFrameCb(TBCCR1); 
    109114            } 
    110115         } else { 
    111116            // SFD pin is low: this was the end of a frame 
    112             if (radiotimer_vars.endOfFrameCb!=NULL) { 
    113                radiotimer_vars.endOfFrameCb(TBCCR1); 
     117            if (radiotimer_vars.endFrameCb!=NULL) { 
     118               radiotimer_vars.endFrameCb(TBCCR1); 
    114119            } 
    115120         } 
    116121         break; 
    117122      case 0x0004: // CCR2 fires 
     123         if (radiotimer_vars.compareCb!=NULL) { 
     124            radiotimer_vars.compareCb(); 
     125         } 
    118126         break; 
    119127      case 0x0006: // CCR3 fires 
  • trunk/firmware/openos/projects/telosb/01-bsp/01bsp_radio.c

    r1453 r1459  
    66 
    77#include "stdint.h" 
     8#include "string.h" 
    89#include "board.h" 
    910#include "radio.h" 
    1011#include "leds.h" 
    1112 
     13//=========================== defines ========================================= 
     14 
    1215#define LENGTH_PACKET 100 
    1316#define CHANNEL       11 
     17 
     18//=========================== variables ======================================= 
     19 
     20void cb_radioTimerOverflows(); 
     21void cb_radioTimerCompare(); 
     22void cb_startFrame(uint16_t timestamp); 
     23void cb_endFrame(uint16_t timestamp); 
     24 
     25typedef struct { 
     26   uint8_t radio_busy; 
     27   uint8_t num_overflow; 
     28   uint8_t num_compare; 
     29   uint8_t num_startFrame; 
     30   uint8_t num_endFrame; 
     31} app_vars_t; 
     32 
     33app_vars_t app_vars; 
     34 
     35//=========================== main ============================================ 
    1436 
    1537/** 
     
    2143   uint8_t i; 
    2244    
    23    // initialize 
     45   // clear local variables 
     46   memset(&app_vars,0,sizeof(app_vars_t)); 
     47    
     48   // initialize board 
    2449   board_init(); 
     50    
     51   // add callback functions from radio 
     52   radio_setOverflowCb(cb_radioTimerOverflows); 
     53   radio_setCompareCb(cb_radioTimerCompare); 
     54   radio_setStartFrameCb(cb_startFrame); 
     55   radio_setEndFrameCb(cb_endFrame); 
    2556    
    2657   // prepare packet 
     
    3566   radio_txEnable(); 
    3667   radio_txNow(); 
    37    radio_waitTxDone(); 
     68   app_vars.radio_busy = 1; 
     69   while (app_vars.radio_busy==1); 
    3870   radio_rfOff(); 
    3971   led_radio_toggle(); 
     
    4274   board_sleep(); 
    4375} 
     76 
     77//=========================== callbacks ======================================= 
     78 
     79void cb_radioTimerOverflows() { 
     80   app_vars.num_overflow++; 
     81} 
     82 
     83void cb_radioTimerCompare() { 
     84   app_vars.num_compare++; 
     85} 
     86 
     87void cb_startFrame(uint16_t timestamp) { 
     88   app_vars.num_startFrame++; 
     89} 
     90 
     91void cb_endFrame(uint16_t timestamp) { 
     92   app_vars.radio_busy = 0; 
     93   app_vars.num_endFrame++; 
     94} 
Note: See TracChangeset for help on using the changeset viewer.