Rev 552 | Rev 588 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 552 | Rev 575 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | /** Initialize character device. |
34 | /** Initialize character device. |
35 | * |
35 | * |
36 | * @param chardev Character device. |
36 | * @param chardev Character device. |
37 | * @param op Implementation of character device operations. |
37 | * @param op Implementation of character device operations. |
38 | */ |
38 | */ |
39 | void chardev_initialize(chardev_t *chardev, chardev_operations_t *op) |
39 | void chardev_initialize(char *name,chardev_t *chardev, |
- | 40 | chardev_operations_t *op) |
|
40 | { |
41 | { |
- | 42 | chardev->name = name; |
|
- | 43 | ||
41 | waitq_initialize(&chardev->wq); |
44 | waitq_initialize(&chardev->wq); |
42 | spinlock_initialize(&chardev->lock, "chardev"); |
45 | spinlock_initialize(&chardev->lock, "chardev"); |
43 | chardev->counter = 0; |
46 | chardev->counter = 0; |
44 | chardev->index = 0; |
47 | chardev->index = 0; |
45 | chardev->op = op; |
48 | chardev->op = op; |
Line 54... | Line 57... | ||
54 | { |
57 | { |
55 | spinlock_lock(&chardev->lock); |
58 | spinlock_lock(&chardev->lock); |
56 | chardev->counter++; |
59 | chardev->counter++; |
57 | if (chardev->counter == CHARDEV_BUFLEN - 1) { |
60 | if (chardev->counter == CHARDEV_BUFLEN - 1) { |
58 | /* buffer full => disable device interrupt */ |
61 | /* buffer full => disable device interrupt */ |
59 | chardev->op->suspend(); |
62 | chardev->op->suspend(chardev); |
60 | } |
63 | } |
61 | 64 | ||
62 | putchar(ch); |
65 | putchar(ch); |
63 | chardev->buffer[chardev->index++] = ch; |
66 | chardev->buffer[chardev->index++] = ch; |
64 | chardev->index = chardev->index % CHARDEV_BUFLEN; /* index modulo size of buffer */ |
67 | chardev->index = chardev->index % CHARDEV_BUFLEN; /* index modulo size of buffer */ |