Subversion Repositories Code-Repo

Rev

Rev 113 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 113 Rev 114
Line 1... Line 1...
1
#include "buffer.h"
1
#include "buffer.h"
2
#include "maindefs.h"
2
#include "maindefs.h"
-
 
3
#include "pwm.h"
3
 
4
 
4
#pragma udata buffer
5
#pragma udata buffer
5
unsigned char buffer[BUFFER_SIZE];
6
unsigned char buffer[BUFFER_SIZE];
6
#pragma udata
7
#pragma udata
7
BUFFER_DATA *buffer_data;
8
BUFFER_DATA *buffer_data;
Line 15... Line 16...
15
}
16
}
16
 
17
 
17
char buffer_insert_one(unsigned char c) {
18
char buffer_insert_one(unsigned char c) {
18
    if (BUFFER_SIZE - buffer_data->stored_length == 0) {
19
    if (BUFFER_SIZE - buffer_data->stored_length == 0) {
19
        DBG_PRINT_BUFFER("Buffer: (ERROR) Not enough free space for insert\r\n");
20
        DBG_PRINT_BUFFER("Buffer: (ERROR) Not enough free space for insert\r\n");
-
 
21
        pwm_LED_on();   // Turn on LED to indicate full buffer
20
        return -1;
22
        return -1;
21
    }
23
    }
22
 
24
 
23
    // Update the amount of used space in the buffer
25
    // Update the amount of used space in the buffer
24
    buffer_data->stored_length += 1;
26
    buffer_data->stored_length += 1;
Line 37... Line 39...
37
    unsigned char i;
39
    unsigned char i;
38
 
40
 
39
    // Make sure we have enough space to store message
41
    // Make sure we have enough space to store message
40
    if (length > BUFFER_SIZE - buffer_data->stored_length) {
42
    if (length > BUFFER_SIZE - buffer_data->stored_length) {
41
        DBG_PRINT_BUFFER("Buffer: (ERROR) Not enough free space for insert\r\n");
43
        DBG_PRINT_BUFFER("Buffer: (ERROR) Not enough free space for insert\r\n");
-
 
44
        pwm_LED_on();   // Turn on LED to indicate full buffer
42
        return -1;
45
        return -1;
43
    }
46
    }
44
 
47
 
45
    // Update the amount of used space in the buffer
48
    // Update the amount of used space in the buffer
46
    buffer_data->stored_length += length;
49
    buffer_data->stored_length += length;
Line 61... Line 64...
61
    unsigned char i;
64
    unsigned char i;
62
 
65
 
63
    // Make sure requested data is less than size of stored data
66
    // Make sure requested data is less than size of stored data
64
    if (length > buffer_data->stored_length) {
67
    if (length > buffer_data->stored_length) {
65
        DBG_PRINT_BUFFER("Buffer: (ERROR) Read length exceedes stored length\r\n");
68
        DBG_PRINT_BUFFER("Buffer: (ERROR) Read length exceedes stored length\r\n");
-
 
69
        pwm_LED_on();   // Turn on LED to indicate full buffer
66
        return -1;
70
        return -1;
67
    }
71
    }
68
 
72
 
69
    // Update the amount of used space in the buffer
73
    // Update the amount of used space in the buffer
70
    buffer_data->stored_length -= length;
74
    buffer_data->stored_length -= length;