For BU9480F D-A Conv.

Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Fri Sep 03 08:01:53 2010 +0000
Revision:
1:02bfb013660c
Parent:
0:805cffac956b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lynxeyed_atsu 0:805cffac956b 1 #include "mbed.h"
lynxeyed_atsu 0:805cffac956b 2 #include "string"
lynxeyed_atsu 0:805cffac956b 3 #include "_bitio.h"
lynxeyed_atsu 0:805cffac956b 4
lynxeyed_atsu 0:805cffac956b 5
lynxeyed_atsu 0:805cffac956b 6 FILE *infp, *outfp;
lynxeyed_atsu 0:805cffac956b 7 int getcount, putcount;
lynxeyed_atsu 0:805cffac956b 8 Uint bitbuf;
lynxeyed_atsu 0:805cffac956b 9
lynxeyed_atsu 0:805cffac956b 10 void init_bit_o(void)
lynxeyed_atsu 0:805cffac956b 11 {
lynxeyed_atsu 0:805cffac956b 12 putcount = 8; bitbuf = 0;
lynxeyed_atsu 0:805cffac956b 13 }
lynxeyed_atsu 0:805cffac956b 14
lynxeyed_atsu 0:805cffac956b 15 void init_bit_i(void)
lynxeyed_atsu 0:805cffac956b 16 {
lynxeyed_atsu 0:805cffac956b 17 getcount = 0; bitbuf = 0;
lynxeyed_atsu 0:805cffac956b 18 }
lynxeyed_atsu 0:805cffac956b 19
lynxeyed_atsu 0:805cffac956b 20
lynxeyed_atsu 0:805cffac956b 21 Uint getbit(void)
lynxeyed_atsu 0:805cffac956b 22 {
lynxeyed_atsu 0:805cffac956b 23 int flag;
lynxeyed_atsu 0:805cffac956b 24 if (--getcount >= 0) return (bitbuf >> getcount) & 1U;
lynxeyed_atsu 0:805cffac956b 25 getcount = 7;
lynxeyed_atsu 0:805cffac956b 26 if((flag = fgetc(infp))==EOF)return OVERRUN;
lynxeyed_atsu 0:805cffac956b 27 else bitbuf = flag;
lynxeyed_atsu 0:805cffac956b 28 return (bitbuf >> 7) & 1U;
lynxeyed_atsu 0:805cffac956b 29 }
lynxeyed_atsu 0:805cffac956b 30
lynxeyed_atsu 0:805cffac956b 31 Uint getbits(int n)
lynxeyed_atsu 0:805cffac956b 32 {
lynxeyed_atsu 0:805cffac956b 33 Uint x = 0;
lynxeyed_atsu 0:805cffac956b 34 if (n < 1 || 25 < n) return 0;
lynxeyed_atsu 0:805cffac956b 35 while (n > getcount) {
lynxeyed_atsu 0:805cffac956b 36 n -= getcount;
lynxeyed_atsu 0:805cffac956b 37 x |= rightbits(getcount, bitbuf) << n;
lynxeyed_atsu 0:805cffac956b 38 bitbuf = fgetc(infp); getcount = 8;
lynxeyed_atsu 0:805cffac956b 39 }
lynxeyed_atsu 0:805cffac956b 40 getcount -= n;
lynxeyed_atsu 0:805cffac956b 41 return x | rightbits(n, bitbuf >> getcount);
lynxeyed_atsu 0:805cffac956b 42 }
lynxeyed_atsu 0:805cffac956b 43
lynxeyed_atsu 0:805cffac956b 44
lynxeyed_atsu 0:805cffac956b 45 void putbit(Uint bit)
lynxeyed_atsu 0:805cffac956b 46 {
lynxeyed_atsu 0:805cffac956b 47 putcount--;
lynxeyed_atsu 0:805cffac956b 48 if (bit != 0) bitbuf |= (1 << putcount);
lynxeyed_atsu 0:805cffac956b 49 if (putcount == 0) {
lynxeyed_atsu 0:805cffac956b 50 if (fputc(bitbuf, outfp) == EOF) error("can't write\r\n");
lynxeyed_atsu 0:805cffac956b 51 bitbuf = 0; putcount = 8;
lynxeyed_atsu 0:805cffac956b 52 }
lynxeyed_atsu 0:805cffac956b 53 }
lynxeyed_atsu 0:805cffac956b 54
lynxeyed_atsu 0:805cffac956b 55
lynxeyed_atsu 0:805cffac956b 56 void putbits(int n, Uint x)
lynxeyed_atsu 0:805cffac956b 57 {
lynxeyed_atsu 0:805cffac956b 58 if (n < 1 || 25 < n) return;
lynxeyed_atsu 0:805cffac956b 59 while (n >= putcount) {
lynxeyed_atsu 0:805cffac956b 60 n -= putcount;
lynxeyed_atsu 0:805cffac956b 61 bitbuf |= rightbits(putcount, x >> n);
lynxeyed_atsu 0:805cffac956b 62 if (fputc(bitbuf, outfp) == EOF) error("cant write\r\n");
lynxeyed_atsu 0:805cffac956b 63 bitbuf = 0U; putcount = 8;
lynxeyed_atsu 0:805cffac956b 64 }
lynxeyed_atsu 0:805cffac956b 65 putcount -= n;
lynxeyed_atsu 0:805cffac956b 66 bitbuf |= rightbits(n, x) << putcount;
lynxeyed_atsu 0:805cffac956b 67 }