Changeset 1111
- Timestamp:
- 08/22/2010 01:21:15 PM (18 months ago)
- Location:
- nano-RK/projects/networking/pcf_tdma/adc_example
- Files:
-
- 4 edited
-
adc_client/main.c (modified) (9 diffs)
-
adc_client/makefile (modified) (1 diff)
-
adc_client/nrk_cfg.h (modified) (1 diff)
-
adc_gw/main.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nano-RK/projects/networking/pcf_tdma/adc_example/adc_client/main.c
r1108 r1111 32 32 #include <nrk_stats.h> 33 33 #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 44 uint32_t mac_address; 35 45 36 46 NRK_STK rx_task_stack[NRK_APP_STACKSIZE]; … … 43 53 44 54 void nrk_create_taskset(); 45 55 void nrk_register_drivers(); 46 56 47 57 tdma_info tx_tdma_fd; … … 51 61 uint8_t tx_buf[TDMA_MAX_PKT_SIZE]; 52 62 53 uint16_t mac_address;63 uint16_t adc_buf[8]; 54 64 55 65 int … … 67 77 68 78 nrk_time_set(0,0); 79 nrk_register_drivers(); 69 80 nrk_create_taskset (); 70 81 nrk_start(); … … 75 86 void tx_task() 76 87 { 77 int8_t v ;78 uint8_t len,cnt ;88 int8_t v,fd; 89 uint8_t len,cnt,chan; 79 90 80 91 … … 83 94 while(!tdma_started()) nrk_wait_until_next_period(); 84 95 85 cnt=0; 96 v=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; 86 104 87 105 while(1) { 88 106 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; 92 124 93 125 v=tdma_send(&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING ); 94 126 if(v==NRK_OK) 95 127 { 96 nrk_kprintf( PSTR("App Packet Sent\ n"));128 nrk_kprintf( PSTR("App Packet Sent\r\n")); 97 129 } 98 130 } … … 105 137 int8_t v; 106 138 uint8_t len,i; 139 uint8_t chan; 107 140 108 141 … … 120 153 // nrk_sw_wdt_start(0); 121 154 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 177 tdma_init(TDMA_CLIENT, chan, mac_address); 125 178 126 179 127 180 while(!tdma_started()) nrk_wait_until_next_period(); 128 181 129 v=tdma_tx_slot_add(mac_address);130 182 131 183 if(v!=NRK_OK ) nrk_kprintf(PSTR("Could not add slot!\r\n")); … … 185 237 } 186 238 187 239 void nrk_register_drivers() 240 { 241 int8_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 250 val=nrk_register_driver( &dev_manager_adc,ADC_DEV_MANAGER); 251 if(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 25 25 # For example: 26 26 SRC += $(ROOT_DIR)/src/net/pcf_tdma/$(RADIO)/pcf_tdma.c 27 27 SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/adc_driver.c 28 28 29 29 # Add extra includes files. -
nano-RK/projects/networking/pcf_tdma/adc_example/adc_client/nrk_cfg.h
r1108 r1111 57 57 #define NRK_MAX_TASKS 5 58 58 59 #define NRK_MAX_DRIVER_CNT 1 59 60 60 61 -
nano-RK/projects/networking/pcf_tdma/adc_example/adc_gw/main.c
r1109 r1111 32 32 #include <nrk_stats.h> 33 33 #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 40 uint32_t mac_address; 35 41 36 42 NRK_STK rx_task_stack[NRK_APP_STACKSIZE]; … … 105 111 uint16_t cnt; 106 112 int8_t v; 107 uint8_t len,i ;113 uint8_t len,i,chan; 108 114 109 115 … … 121 127 // nrk_sw_wdt_start(0); 122 128 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 151 tdma_init(TDMA_HOST, chan, mac_address); 124 152 125 153 // Change these parameters anytime you want... … … 144 172 printf( "Node: %u [",rx_tdma_fd.src ); 145 173 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]) ); 147 175 nrk_kprintf( PSTR("]\r\n")); 148 176 }
Note: See TracChangeset
for help on using the changeset viewer.
