FFS(3)				   BSD Library Functions Manual 			   FFS(3)

NAME
     ffs, ffsl, ffsll, fls, flsl, flsll -- find first or last bit set in a bit string

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <strings.h>

     int
     ffs(int value);

     int
     ffsl(long value);

     int

     int
     ffsll(long long value);

     fls(int value);

     int
     flsl(long value);

     int
     flsll(long long value);

DESCRIPTION
     The ffs(), ffsl() and ffsll() functions find the first bit set (beginning with the least
     significant bit) in value and return the index of that bit.

     The fls(), flsl() and flsll() functions find the last bit set in value and return the index
     of that bit.

     Bits are numbered starting at 1 (the least significant bit).  A return value of zero from
     any of these functions means that the argument was zero.

SEE ALSO
     bitstring(3)

HISTORY
     The ffs() function appeared in 4.3BSD.  Its prototype existed previously in <string.h>
     before it was moved to <strings.h> for IEEE Std 1003.1-2001 (``POSIX.1'') compliance.

     The ffsl(), fls() and flsl() functions appeared in FreeBSD 5.3.  The ffsll() and flsll()
     functions appeared in FreeBSD 7.1.

BSD					 October 26, 2008				      BSD


Posted by 깍수
,

Memory (Shift+Alt+M) 창을 열려면 Set Dump Address 이름으로 Pop-up 창이 뜨게 되는데

Dump Address / Expression 에 해당 메모리 정보를 입력 한다. 단 Linux 환겨일 경우 MMU에 의해 Virtual Memory

주소를 사용해야 하기 때문에 주소 앞에 "A:"를 넣어 준다. ex) A:7E00F114

그리고 Memory Type에 PM으로 선택하면 된다.



Posted by 깍수
,



Posted by 깍수
,

1. gettimeofday

#include <sys/time.h>

#include <unistd.h>


int gettimeofday(struct timeval *tv, struct timezone *tz);

int settimeofday(const struct timeval *tv, const struct timezone *tz);


struct timeval {

    long tv_sec;

    long tv_usec;

}


struct timezone {

    long tz_minuteswest;

    long tz_dsttime;

}


ex) gettimeofday

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>

int main( int argc, char ** argv )
{
    struct timeval tmstart, tmend;
    unsigned long elapsed;

    for(;;)
    {
        gettimeofday(&tmstart, NULL);
        usleep( 20000 );

        gettimeofday(&tmend, NULL);
        elapsed = (tmend.tv_sec - tmstart.tv_sec)*1000000 + tmend.tv_usec - tmstart.tv_usec;

        printf("elapsed time : %ld\n", elapsed);

       

        // 만약 시간을 뒤로 1시간 돌리고 싶다면

        tmend.tv_sec - 3600;

        settimeofday(&tmend, NULL);
    }

return 0;
}


2. clock_gettime

nanoseconds 까지 측정 가능한 함수 이다.

struct timespec {

    time_t tv_sec;     /* seconds */

    long tv_nsec;     /* nanoseconds */


ex) clock_gettime

컴파일시 -lrt 옵션을 넣어서 해당 library를 링크 시켜줘야 한다.

#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main( int argc, char ** argv )
{

        const unsigned long long nano = 1000000000;
        unsigned long long t1, t2;

        struct timespec tm;

        for(;;)
        {

                clock_gettime( CLOCK_REALTIME, &tm );
                t1 = tm.tv_nsec + tm.tv_sec * nano;

                usleep( 20000 );

                clock_gettime( CLOCK_REALTIME, &tm );
                t2 = tm.tv_nsec + tm.tv_sec * nano;

                printf( "delay: %ld\n", ( t2 - t1 ) / 1000 );
        }

        return 0;

}


아래와 같이 함수를 만들어 사용하면 ms 시간을 얻어 편리하게 사용할 수 있을 것으로 보인다.

static long getTime(void)
{
    struct timeval  now;
    gettimeofday(&now, NULL);
    return (long)(now.tv_sec*1000 + now.tv_usec/1000);
}


static long _getTime(void)
{
    struct timespec now;
    clock_gettime(CLOCK_MONOTONIC, &now);
    return now.tv_sec*1000000 + now.tv_nsec/1000;
}



'Embedded Linux > Tip' 카테고리의 다른 글

dpkg를 이용한 package 정보를 알고 싶을 때  (0) 2014.08.14
[vim] Copy&Paste  (0) 2014.04.23
Target board에 대한 Toolchain 선택  (1) 2013.12.04
Posted by 깍수
,

#include <semaphore.h>


int sem_init(sem_t *sem, int pshared, unsigned int value);

: 3번째 Parameter value의 값으로 semaphore 변수 초기값을 정하게 된다.

int sem_wait(sem_t *sem);

: semaphore 값이 0일 경우 대기하게 되고 아닐 경우 semaphore 값을 감소 시키고 다음 문장을 실행 하게 된다.

int sem_post(sem_t *sem);

: semaphore 값 증가

int sem_destroy(sem_t *sem);


#include <semaphore.h>

.

sem_t bin_sem;

.


int main(int argc, char **argv)

{

.

.

     ret = sem_init(&bin_sem, 0, 0);

.

.

    sem_destroy(&bin_sem);


     return 0;

}


이 semaphore을 사용하게 되면 원하는 Thread 함수를 특정 순서에 맞게 제어가 가능하다

예를 들어 항상 먼저 실행 되어야할 순서가 있다면  semaphore 변수을 0으로 초기화 다음 먼저 실행 되어야 할 

함수의 경우 sem_post()함수를 호출하게 하고 다른 함수를 sem_wait()를 호출하게 하면 항상 순차적으로 동작 하게 된다.


Posted by 깍수
,

동기화 Mutex

Embedded Linux 2014. 8. 22. 20:44


#include <pthread.h>


int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);

int pthread_mutex_lock(pthread_mutex_t *mutex);

int pthread_mutex_unlock(pthread_mutex_t *mutex);

int pthread_mutex_destroy(pthread_mutex_t *mutex);

#include <pthread.h>

.

.

pthread_mutex_t mutex;

.

int main(int argc, char **argv)

{

    int state;

.

.   

    state = pthread_mutex_init(&mutex, NULL);

.

.

    // pthread1, 2 생성

.

.

   pthread_mutex_destroy(&mutex);

   return 0;

}


// pthread function에서 Critical section 설정

pthread_mutex_lock(&mutex);

.

.

pthread_mutex_unlock(&mutex);




Posted by 깍수
,

gcc로 컴파일 할 경우 -D_REENTRANT상수을 선언 하여 Thread_safe함수를 사용할 수 있도록 옵션을 꼭 사용해야

하며 -lpthread 이와 같이 Library를 링크 시켜야 한다.


* int pthread_create(pthread_t *thread, 

   pthread_attr_t *attr, 

   void *(*start_rountine)(void *), 

   void *arg

   );

Parameter attr의 경우 일반적으로 NULL 값을 사용한다.


* int pthread_join(pthread_t thread, void **retval);

Window programming에서 WaitForSingleObject() 함수와 유사한 기능을 하는 것으로 보인다.

아래와 같이 해당 thread_function이 종료가 될 때까지 main() 함수는 대기 하게 된다.

#include <pthread.h>


static void *handle_function(void *arg);


int main(int argc, char **argv)

{

    pthread_t thread_id;

    void *thread_retval;

    .

    .

    state = pthread_create(&thread_id, NULL, handle_function, NULL);

    .

    .

    state = pthread_join(thread_id, &thread_retval);

    .

    .

    return 0;

}


static void *handle_function(void *arg)

{


}


'Embedded Linux' 카테고리의 다른 글

CodeViser의 S3C6410 Interface 설정  (0) 2014.11.18
Semaphore을 이용한 동기화 (binary semaphore)  (0) 2014.08.22
동기화 Mutex  (0) 2014.08.22
Volume was not properly unmounted ...  (0) 2014.07.24
Wireless Tools for Linux  (0) 2014.07.07
Posted by 깍수
,

Where <n> is the required interface : 0=auto, 1=analog, 2=hdmi. To force the Raspberry Pi to use the analog output :


#amixer cset numid=3 n


'Embedded Linux > Raspberry Pi b+' 카테고리의 다른 글

Bluetooth 헤드셋 연결 (A2DP)  (0) 2014.08.22
Posted by 깍수
,

1. 필요한 패키지 설치

#sudo apt-get install bluetooth bluez mpg321

필자의 경우 위의 mpg321 Player를 설치 하였으나 mplayer or cmus를 설치 하여도 된다.


2. 유저를 bluetooth 그룹에 등록

#sudo gpasswd -a pi bluetooth

위의 pi는 사용자 계정이며 현재 자기가 사용하고 있는 계정을 쓰면 된다.


3. alsa 설정 파일 생성 및 블루투스 오디오 설정

1) .asoundrc 파일 생성

#vi ~/.asoundrc

pcm.bluetooth {

type bluetooth

device xx:xx:xx:xx:xx:xx

}


2) bluetooth audio 설정

#vi /etc/bluetooth/audio.conf

[General] Section 아래에 다음과 같이 추가 한다.

Disable=Media

Enable=Socket

위와 같이 설정한 다음 리부팅 or sudo /etc/init.d/bluetooth restart해서 bluetooth service를 재시작 한다.


4. 블루투스 헤드셋에 연결

1) bluetooth-agent, bluez-test-audio

#bluetooth-agent --adapter hci0 0000 xx:xx:xx:xx:xx:xx

#bluez-test-audio connect xx:xx:xx:xx:xx:xx


2) bluez-simple-agent

#bluez-simple-agent hci0 xx:xx:xx:xx:xx:xx

#mpg321 -a bluetooth -g 10 ----.mp3

블루투스 헤드셋 디바이스의 경우 BDADDR는 페어링 모드를(디바이스) 진입한 다음 hcitool scan을 하면

해당 디바이스 BDADDR을 알 수 있다.


5. 기타

1) 다른 Player 사용법

- mplayer

#mplayer -ao alsa:device=bluetooth ----.mp3 --af=resample=22100:0:0


- cmus

cmus player를 사용하기전 alsa bluetooth device 설정

#dsp.alsa.device bluetooth

#output plugin alsa


2) PI 부팅할 때마다 자동으로 헤드셋(스피커)에 연결됨

#bluez-test-device trusted xx:xx:xx:xx:xx:xx yes

#bluez-test-device trusted xx:xx:xx:xx:xx:xx - 확인할 경우 결과값은 1이 나오면 설정이 완료됨




'Embedded Linux > Raspberry Pi b+' 카테고리의 다른 글

alsa mixer를 이용한 audio output 설정  (0) 2014.08.22
Posted by 깍수
,

dpkg -l(소문자 L)  패키지명

: 패키지 정보를 보여 준다.


- dpkg -S 파일명

: 해당 파일에 대한 패키지 명을 알려 준다.


- dpkg -L 패키지명

: 해당 패키지의 파일들을 보여 준다.



'Embedded Linux > Tip' 카테고리의 다른 글

시간 측정 방법  (0) 2014.08.26
[vim] Copy&Paste  (0) 2014.04.23
Target board에 대한 Toolchain 선택  (1) 2013.12.04
Posted by 깍수
,