Changeset 99
- Timestamp:
- 06/12/2007 11:47:52 PM (5 years ago)
- Location:
- nano-RK
- Files:
-
- 4 added
- 5 edited
-
projects/basic_adc/main.c (modified) (2 diffs)
-
projects/basic_sensors (added)
-
projects/basic_sensors/main.c (added)
-
projects/basic_sensors/makefile (added)
-
projects/basic_sensors/nrk_cfg.h (added)
-
src/drivers/platform/firefly2_2/include/adc_driver.h (modified) (1 diff)
-
src/drivers/platform/firefly2_2/include/ff_basic_sensor.h (modified) (1 diff)
-
src/drivers/platform/firefly2_2/source/adc_driver.c (modified) (1 diff)
-
src/drivers/platform/firefly2_2/source/ff_basic_sensor.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nano-RK/projects/basic_adc/main.c
r96 r99 44 44 { 45 45 uint16_t cnt; 46 int8_t fd,val ;46 int8_t fd,val,chan; 47 47 uint8_t buf; 48 48 … … 56 56 57 57 cnt=0; 58 chan=0; 58 59 while(1) { 59 60 nrk_led_toggle(BLUE_LED); 61 chan++; 62 if(chan>7) chan=0; 60 63 // Example of setting the ADC channel 61 val=nrk_set_status(fd,ADC_CHAN, 0);64 val=nrk_set_status(fd,ADC_CHAN,chan); 62 65 if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to set ADC status\r\n" )); 63 66 val=nrk_read(fd,&buf,1); 64 67 if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to read ADC\r\n" )); 65 printf( "Task1 adc=%d\r\n",buf);68 printf( "Task1 channel=%d adc=%d\r\n",chan,buf); 66 69 nrk_wait_until_next_period(); 67 70 cnt++; -
nano-RK/src/drivers/platform/firefly2_2/include/adc_driver.h
r95 r99 1 1 #include<stdio.h> 2 2 3 // SET/GET STATUS options 3 4 #define ADC_CHAN 1 5 6 // ADC channels 7 #define CHAN_0 0 8 #define CHAN_1 1 9 #define CHAN_2 2 10 #define CHAN_3 3 11 #define CHAN_4 4 12 #define CHAN_5 5 13 #define CHAN_6 6 14 #define CHAN_7 7 4 15 5 16 void delay(); -
nano-RK/src/drivers/platform/firefly2_2/include/ff_basic_sensor.h
r95 r99 1 1 #include<stdio.h> 2 2 3 #define ADC_CHAN 1 3 // GET/SET Status Options 4 #define SENSOR_SELECT 1 5 6 // SET_SENSOR options 7 #define BAT 0 8 #define LIGHT 1 9 #define ACC_X 2 10 #define AUDIO 3 11 #define TEMP 4 12 #define ACC_Y 5 13 #define ACC_Z 6 14 15 16 17 #define PWR_CTRL_MASK 0x80 18 4 19 5 20 void delay(); 6 uint8_t dev_manager_ adc(uint8_t state,uint8_t opt,uint8_t * buffer,uint8_t size);21 uint8_t dev_manager_ff_sensors(uint8_t state,uint8_t opt,uint8_t * buffer,uint8_t size); 7 22 uint16_t get_adc_val(); 8 23 -
nano-RK/src/drivers/platform/firefly2_2/source/adc_driver.c
r95 r99 60 60 if(opt&READ_FLAG) 61 61 { 62 62 RETURN NRK_OK; 63 63 } 64 64 if(opt&WRITE_FLAG) 65 65 { 66 66 RETURN NRK_ERROR; 67 67 } 68 68 if(opt&APPEND_FLAG) 69 69 { 70 70 RETURN NRK_ERROR; 71 71 } 72 72 if(opt&(READ_FLAG|WRITE_FLAG|APPEND_FLAG)==0) -
nano-RK/src/drivers/platform/firefly2_2/source/ff_basic_sensor.c
r95 r99 1 1 #include <nrk_driver_list.h> 2 2 #include <nrk_driver.h> 3 #include < adc_driver.h>3 #include <ff_basic_sensor.h> 4 4 #include <include.h> 5 5 #include <stdio.h> … … 9 9 #include <stdint.h> 10 10 11 #define ADC_SETUP_DELAY 500 11 #define ADC_STARTUP_DELAY 1000 12 #define ADC_SETUP_DELAY 200 12 13 13 14 uint8_t channel; … … 44 45 } while (0) 45 46 46 uint8_t dev_manager_ adc(uint8_t action,uint8_t opt,uint8_t *buffer,uint8_t size)47 uint8_t dev_manager_ff_sensors(uint8_t action,uint8_t opt,uint8_t *buffer,uint8_t size) 47 48 { 48 49 uint8_t count=0; … … 54 55 { 55 56 case INIT: 57 // Set the pwr ctrl pin as output 58 DDRF = PWR_CTRL_MASK; 59 PORTF |= PWR_CTRL_MASK; 56 60 init_adc(); 57 61 return 1; … … 60 64 if(opt&READ_FLAG) 61 65 { 62 66 // Turn on Sensor Node Power 67 PORTF &= ~(PWR_CTRL_MASK); 68 channel=0; 69 ADC_SET_CHANNEL (0); 70 nrk_spin_wait_us(ADC_STARTUP_DELAY); 71 return NRK_OK; 63 72 } 64 73 if(opt&WRITE_FLAG) 65 74 { 66 75 return NRK_ERROR; 67 76 } 68 77 if(opt&APPEND_FLAG) 69 78 { 70 79 return NRK_ERROR; 71 80 } 72 81 if(opt&(READ_FLAG|WRITE_FLAG|APPEND_FLAG)==0) … … 77 86 78 87 case READ: 79 for(count=0;count<size;count++) 80 { 88 count=0; 81 89 /* Conversion to 8-bit value*/ 82 90 uint16_t val=get_adc_val(); 83 91 buffer[count]=val >>2 & 0xFF; 84 } 92 count++; 85 93 return count; 86 94 87 95 case CLOSE: 96 // Turn off sensor power 97 PORTF |= PWR_CTRL_MASK; 88 98 return NRK_OK; 89 99 90 100 case GET_STATUS: 91 101 // use "key" here 92 if(key== ADC_CHAN) return channel;102 if(key==SENSOR_SELECT) return channel; 93 103 return NRK_ERROR; 94 104 95 105 case SET_STATUS: 96 // use "key" and " opt" here97 if(key== ADC_CHAN)106 // use "key" and "value" here 107 if(key==SENSOR_SELECT) 98 108 { 99 channel=opt; 109 if(value<0 || value>7) 110 { 111 _nrk_errno_set(1); 112 return NRK_ERROR; 113 } 114 channel=value; 100 115 ADC_SET_CHANNEL (channel); 101 116 nrk_spin_wait_us(ADC_SETUP_DELAY); 117 return NRK_OK; 102 118 } 103 119 return NRK_ERROR; … … 111 127 { 112 128 // Initialize values here 113 DDRA = 0x80;114 129 ADC_INIT (); 115 130 ADC_ENABLE ();
Note: See TracChangeset
for help on using the changeset viewer.
