OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [fs/] [jffs2/] [v2_0/] [src/] [pushpull.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * JFFS2 -- Journalling Flash File System, Version 2.
3
 *
4
 * Copyright (C) 2001, 2002 Red Hat, Inc.
5
 *
6
 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
7
 *
8
 * For licensing information, see the file 'LICENCE' in this directory.
9
 *
10
 * $Id: pushpull.h,v 1.1.1.1 2004-02-14 13:29:20 phoenix Exp $
11
 *
12
 */
13
 
14
#ifndef __PUSHPULL_H__
15
#define __PUSHPULL_H__
16
 
17
#include <linux/errno.h>
18
 
19
struct pushpull {
20
        unsigned char *buf;
21
        unsigned int buflen;
22
        unsigned int ofs;
23
        unsigned int reserve;
24
};
25
 
26
 
27
static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve)
28
{
29
        pp->buf = buf;
30
        pp->buflen = buflen;
31
        pp->ofs = ofs;
32
        pp->reserve = reserve;
33
}
34
 
35
static inline int pushbit(struct pushpull *pp, int bit, int use_reserved)
36
{
37
        if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) {
38
                return -ENOSPC;
39
        }
40
 
41
        if (bit) {
42
                pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7)));
43
        }
44
        else {
45
                pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7)));
46
        }
47
        pp->ofs++;
48
 
49
        return 0;
50
}
51
 
52
static inline int pushedbits(struct pushpull *pp)
53
{
54
        return pp->ofs;
55
}
56
 
57
static inline int pullbit(struct pushpull *pp)
58
{
59
        int bit;
60
 
61
        bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1;
62
 
63
        pp->ofs++;
64
        return bit;
65
}
66
 
67
static inline int pulledbits(struct pushpull *pp)
68
{
69
        return pp->ofs;
70
}
71
 
72
#endif /* __PUSHPULL_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.