Changeset 99


Ignore:
Timestamp:
06/12/2007 11:47:52 PM (5 years ago)
Author:
agr
Message:

sensor driver added

Location:
nano-RK
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • nano-RK/projects/basic_adc/main.c

    r96 r99  
    4444{ 
    4545uint16_t cnt; 
    46 int8_t fd,val; 
     46int8_t fd,val,chan; 
    4747uint8_t buf; 
    4848 
     
    5656   
    5757  cnt=0; 
     58  chan=0; 
    5859  while(1) { 
    5960        nrk_led_toggle(BLUE_LED); 
     61        chan++; 
     62        if(chan>7) chan=0; 
    6063        // Example of setting the ADC channel 
    61         val=nrk_set_status(fd,ADC_CHAN,0); 
     64        val=nrk_set_status(fd,ADC_CHAN,chan); 
    6265        if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to set ADC status\r\n" )); 
    6366        val=nrk_read(fd,&buf,1); 
    6467        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); 
    6669        nrk_wait_until_next_period(); 
    6770        cnt++; 
  • nano-RK/src/drivers/platform/firefly2_2/include/adc_driver.h

    r95 r99  
    11#include<stdio.h> 
    22 
     3// SET/GET STATUS options 
    34#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 
    415 
    516void delay(); 
  • nano-RK/src/drivers/platform/firefly2_2/include/ff_basic_sensor.h

    r95 r99  
    11#include<stdio.h> 
    22 
    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 
    419 
    520void delay(); 
    6 uint8_t dev_manager_adc(uint8_t state,uint8_t opt,uint8_t * buffer,uint8_t size); 
     21uint8_t dev_manager_ff_sensors(uint8_t state,uint8_t opt,uint8_t * buffer,uint8_t size); 
    722uint16_t get_adc_val(); 
    823 
  • nano-RK/src/drivers/platform/firefly2_2/source/adc_driver.c

    r95 r99  
    6060                    if(opt&READ_FLAG) 
    6161                    { 
    62                      
     62                        RETURN NRK_OK;  
    6363                    } 
    6464                    if(opt&WRITE_FLAG) 
    6565                    { 
    66  
     66                        RETURN NRK_ERROR;  
    6767                    } 
    6868                    if(opt&APPEND_FLAG) 
    6969                    { 
    70  
     70                        RETURN NRK_ERROR;  
    7171                    } 
    7272                    if(opt&(READ_FLAG|WRITE_FLAG|APPEND_FLAG)==0) 
  • nano-RK/src/drivers/platform/firefly2_2/source/ff_basic_sensor.c

    r95 r99  
    11#include <nrk_driver_list.h> 
    22#include <nrk_driver.h> 
    3 #include <adc_driver.h> 
     3#include <ff_basic_sensor.h> 
    44#include <include.h> 
    55#include <stdio.h> 
     
    99#include <stdint.h> 
    1010 
    11 #define ADC_SETUP_DELAY  500 
     11#define ADC_STARTUP_DELAY  1000 
     12#define ADC_SETUP_DELAY  200 
    1213 
    1314uint8_t channel; 
     
    4445} while (0) 
    4546 
    46 uint8_t dev_manager_adc(uint8_t action,uint8_t opt,uint8_t *buffer,uint8_t size) 
     47uint8_t dev_manager_ff_sensors(uint8_t action,uint8_t opt,uint8_t *buffer,uint8_t size) 
    4748{ 
    4849uint8_t count=0; 
     
    5455     { 
    5556            case INIT:  
     57                        // Set the pwr ctrl pin as output 
     58                        DDRF = PWR_CTRL_MASK; 
     59                        PORTF |= PWR_CTRL_MASK; 
    5660                        init_adc();   
    5761                      return 1; 
     
    6064                    if(opt&READ_FLAG) 
    6165                    { 
    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; 
    6372                    } 
    6473                    if(opt&WRITE_FLAG) 
    6574                    { 
    66  
     75                        return NRK_ERROR; 
    6776                    } 
    6877                    if(opt&APPEND_FLAG) 
    6978                    { 
    70  
     79                        return NRK_ERROR; 
    7180                    } 
    7281                    if(opt&(READ_FLAG|WRITE_FLAG|APPEND_FLAG)==0) 
     
    7786 
    7887             case READ: 
    79                       for(count=0;count<size;count++) 
    80                       {                    
     88                      count=0; 
    8189                              /* Conversion to 8-bit value*/ 
    8290                              uint16_t val=get_adc_val(); 
    8391                              buffer[count]=val >>2 & 0xFF; 
    84                       } 
     92                      count++; 
    8593                      return count; 
    8694 
    8795             case CLOSE: 
     96                        // Turn off sensor power 
     97                        PORTF |= PWR_CTRL_MASK; 
    8898                        return NRK_OK; 
    8999              
    90100             case GET_STATUS: 
    91101                        // use "key" here  
    92                         if(key==ADC_CHAN) return channel; 
     102                        if(key==SENSOR_SELECT) return channel; 
    93103                        return NRK_ERROR; 
    94104                         
    95105             case SET_STATUS: 
    96                         // use "key" and "opt" here 
    97                         if(key==ADC_CHAN)  
     106                        // use "key" and "value" here 
     107                        if(key==SENSOR_SELECT)  
    98108                        { 
    99                                 channel=opt; 
     109                                if(value<0 || value>7)  
     110                                { 
     111                                        _nrk_errno_set(1); 
     112                                        return NRK_ERROR; 
     113                                } 
     114                                channel=value; 
    100115                                ADC_SET_CHANNEL (channel); 
    101  
     116                                nrk_spin_wait_us(ADC_SETUP_DELAY); 
     117                                return NRK_OK; 
    102118                        } 
    103119                        return NRK_ERROR; 
     
    111127{ 
    112128// Initialize values here 
    113   DDRA = 0x80; 
    114129  ADC_INIT (); 
    115130  ADC_ENABLE (); 
Note: See TracChangeset for help on using the changeset viewer.