Changeset 1111


Ignore:
Timestamp:
08/22/2010 01:21:15 PM (18 months ago)
Author:
agr
Message:

updated pcf tdma

Location:
nano-RK/projects/networking/pcf_tdma/adc_example
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nano-RK/projects/networking/pcf_tdma/adc_example/adc_client/main.c

    r1108 r1111  
    3232#include <nrk_stats.h> 
    3333#include <pcf_tdma.h> 
    34  
     34#include <nrk_eeprom.h> 
     35 
     36#include <nrk_driver_list.h> 
     37#include <nrk_driver.h> 
     38#include <adc_driver.h> 
     39 
     40// if SET_MAC is 0, then read MAC from EEPROM 
     41// otherwise use the coded value 
     42#define SET_MAC  0x0000 
     43 
     44uint32_t mac_address; 
    3545 
    3646NRK_STK rx_task_stack[NRK_APP_STACKSIZE]; 
     
    4353 
    4454void nrk_create_taskset(); 
    45  
     55void nrk_register_drivers(); 
    4656 
    4757tdma_info tx_tdma_fd; 
     
    5161uint8_t tx_buf[TDMA_MAX_PKT_SIZE]; 
    5262 
    53 uint16_t mac_address; 
     63uint16_t adc_buf[8]; 
    5464 
    5565int 
     
    6777  
    6878  nrk_time_set(0,0); 
     79  nrk_register_drivers(); 
    6980  nrk_create_taskset (); 
    7081  nrk_start(); 
     
    7586void tx_task() 
    7687{ 
    77 int8_t v; 
    78 uint8_t len,cnt; 
     88int8_t v,fd; 
     89uint8_t len,cnt,chan; 
    7990 
    8091   
     
    8394while(!tdma_started()) nrk_wait_until_next_period(); 
    8495 
    85 cnt=0; 
     96v=tdma_tx_slot_add(mac_address); 
     97 
     98  // Open ADC device as read  
     99  fd=nrk_open(ADC_DEV_MANAGER,READ); 
     100  if(fd==NRK_ERROR) nrk_kprintf( PSTR("Failed to open ADC driver\r\n")); 
     101 
     102  cnt=0; 
     103  chan=0; 
    86104 
    87105  while(1) { 
    88106         
    89         sprintf( tx_buf,"Node MAC: %u cnt: %d\n",mac_address,cnt ); 
    90         cnt++; 
    91         len=strlen(tx_buf)+1; 
     107        for(chan=0; chan<8; chan++ ) 
     108        { 
     109          // Example of setting the ADC channel 
     110          v=nrk_set_status(fd,ADC_CHAN,chan); 
     111          if(v==NRK_ERROR) nrk_kprintf( PSTR("Failed to set ADC status\r\n" )); 
     112          v=nrk_read(fd,&adc_buf[chan],2); 
     113          if(v==NRK_ERROR) nrk_kprintf( PSTR("Failed to read ADC\r\n" )); 
     114        } 
     115         
     116        for(chan=0; chan<8; chan++ ) 
     117        { 
     118                tx_buf[chan*2]=(adc_buf[chan]>>8) & 0xff; 
     119                tx_buf[chan*2+1]=((uint8_t)adc_buf[chan]) & 0xff; 
     120                printf( "chan%d: %d ",chan,adc_buf[chan]); 
     121        } 
     122        nrk_kprintf( PSTR("\r\n" )); 
     123        len=16; 
    92124 
    93125         v=tdma_send(&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING );         
    94126        if(v==NRK_OK) 
    95127                { 
    96                 nrk_kprintf( PSTR("App Packet Sent\n")); 
     128                nrk_kprintf( PSTR("App Packet Sent\r\n")); 
    97129                } 
    98130        } 
     
    105137int8_t v; 
    106138uint8_t len,i; 
     139uint8_t chan; 
    107140 
    108141 
     
    120153// nrk_sw_wdt_start(0); 
    121154 
    122 mac_address=1; 
    123  
    124 tdma_init(TDMA_CLIENT, 13, mac_address); 
     155  chan = 25; 
     156  if (SET_MAC == 0x00) { 
     157 
     158    v = read_eeprom_mac_address (&mac_address); 
     159    if (v == NRK_OK) { 
     160      v = read_eeprom_channel (&chan); 
     161    } 
     162    else { 
     163      while (1) { 
     164        nrk_kprintf (PSTR 
     165                     ("* ERROR reading MAC address, run eeprom-set utility\r\n")); 
     166        nrk_wait_until_next_period (); 
     167      } 
     168    } 
     169  } 
     170  else 
     171    mac_address = SET_MAC; 
     172 
     173  printf ("MAC ADDR: %x\r\n", mac_address & 0xffff); 
     174  printf ("chan = %d\r\n", chan); 
     175 
     176 
     177tdma_init(TDMA_CLIENT, chan, mac_address); 
    125178 
    126179 
    127180while(!tdma_started()) nrk_wait_until_next_period(); 
    128181 
    129 v=tdma_tx_slot_add(mac_address); 
    130182 
    131183if(v!=NRK_OK ) nrk_kprintf(PSTR("Could not add slot!\r\n")); 
     
    185237} 
    186238 
    187  
     239void nrk_register_drivers() 
     240{ 
     241int8_t val; 
     242 
     243// Register the ADC device driver 
     244// Make sure to add:  
     245//     #define NRK_MAX_DRIVER_CNT   
     246//     in nrk_cfg.h 
     247// Make sure to add:  
     248//     SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/adc_driver.c 
     249//     in makefile 
     250val=nrk_register_driver( &dev_manager_adc,ADC_DEV_MANAGER); 
     251if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to load my ADC driver\r\n") ); 
     252 
     253} 
     254 
     255 
  • nano-RK/projects/networking/pcf_tdma/adc_example/adc_client/makefile

    r1108 r1111  
    2525# For example: 
    2626SRC += $(ROOT_DIR)/src/net/pcf_tdma/$(RADIO)/pcf_tdma.c 
    27  
     27SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/adc_driver.c 
    2828 
    2929# Add extra includes files.  
  • nano-RK/projects/networking/pcf_tdma/adc_example/adc_client/nrk_cfg.h

    r1108 r1111  
    5757#define NRK_MAX_TASKS                   5 
    5858 
     59#define NRK_MAX_DRIVER_CNT              1 
    5960                            
    6061 
  • nano-RK/projects/networking/pcf_tdma/adc_example/adc_gw/main.c

    r1109 r1111  
    3232#include <nrk_stats.h> 
    3333#include <pcf_tdma.h> 
    34  
     34#include <nrk_eeprom.h> 
     35 
     36// if SET_MAC is 0, then read MAC from EEPROM 
     37// otherwise use the coded value 
     38#define SET_MAC  0x0000 
     39 
     40uint32_t mac_address; 
    3541 
    3642NRK_STK rx_task_stack[NRK_APP_STACKSIZE]; 
     
    105111uint16_t cnt; 
    106112int8_t v; 
    107 uint8_t len,i; 
     113uint8_t len,i,chan; 
    108114 
    109115 
     
    121127// nrk_sw_wdt_start(0); 
    122128 
    123 tdma_init(TDMA_HOST, 13, 0); 
     129  chan = 25; 
     130  if (SET_MAC == 0x00) { 
     131 
     132    v = read_eeprom_mac_address (&mac_address); 
     133    if (v == NRK_OK) { 
     134      v = read_eeprom_channel (&chan); 
     135    } 
     136    else { 
     137      while (1) { 
     138        nrk_kprintf (PSTR 
     139                     ("* ERROR reading MAC address, run eeprom-set utility\r\n")); 
     140        nrk_wait_until_next_period (); 
     141      } 
     142    } 
     143  } 
     144  else 
     145    mac_address = SET_MAC; 
     146 
     147  printf ("MAC ADDR: %x\r\n", mac_address & 0xffff); 
     148  printf ("chan = %d\r\n", chan); 
     149 
     150 
     151tdma_init(TDMA_HOST, chan, mac_address); 
    124152 
    125153// Change these parameters anytime you want... 
     
    144172        printf( "Node: %u [",rx_tdma_fd.src ); 
    145173        for(i=0; i<8; i++ ) 
    146                 printf( "%u ",rx_buf[i] ); 
     174                printf( "%u ",(uint16_t)((uint16_t)rx_buf[i*2])<<8 | ((uint16_t)rx_buf[i*2+1]) ); 
    147175        nrk_kprintf( PSTR("]\r\n")); 
    148176        } 
Note: See TracChangeset for help on using the changeset viewer.