Project

General

Profile

Revision 1183

Added individual hardware component files

View differences:

trunk/code/projects/diagnostic_station/station/hardware_turntable.c
1
#include "hardware_turntable.h"
2

  
3
void turntable_init ()
4
{
5
	// FIXME implement
6
}
7

  
8
void turntable_rotate_to_position (uint16_t position)
9
{
10
	usb_puts ("# Rotating to position ");
11
	usb_puti (position);
12
	usb_puts (NL);
13
	
14
	// FIXME implement
15
	
16
	usb_puts ("# Robot position reached");
17
}
18

  
trunk/code/projects/diagnostic_station/station/hardware_turntable.h
1
#ifndef _hardware_turntable_h
2
#define _hardware_turntable_h
3

  
4
#include <dragonfly_lib.h>
5
#include "global.h"
6

  
7
void turntable_init (void);
8

  
9
#endif
trunk/code/projects/diagnostic_station/station/hardware_rbom.c
1
#include "hardware_rbom.h"
2

  
3
void rbom_init (void)
4
{
5
	// FIXME implement
6
}
7

  
8
void rbom_set (bool on)
9
{
10
	if (on)
11
	{
12
		usb_puts ("# Turning RBOM light on" NL);
13
		// FIXME implement
14
	}
15
	else
16
	{
17
		usb_puts ("# Turning RBOM light off" NL);
18
		// FIXME implement
19
	}
20
}
21

  
22
uint16_t rbom_read (uint8_t value)
23
{
24
	usb_puts ("# Reading RBOM" NL);
25
	// FIXME implement
26
	
27
	return 0;
28
}
29

  
30
void rbom_update (void)
31
{
32
	// FIXME implement
33
}
trunk/code/projects/diagnostic_station/station/hardware_wall.c
1
#include "hardware_wall.h"
2

  
3
void wall_init ()
4
{
5
	// FIXME implement
6
}
7

  
8
void wall_set_position (uint16_t position)
9
{
10
	usb_puts ("# Moving wall to position ");
11
	usb_puti (position);
12
	usb_puts (NL);
13
	
14
	// FIXME implement
15
	
16
	usb_puts ("# Wall position reached");
17
}
18

  
19
// We might also need this because the wall_set_position might not reach the exact position
20
uint16_t wall_get_position ()
21
{
22
	// FIXME implement
23
	return 0;
24
}
trunk/code/projects/diagnostic_station/station/hardware_encoders.c
1
#include "hardware_encoders.h"
2

  
3
volatile int16_t count_l=0, count_r=0;
4

  
5

  
6
void encoders_init ()
7
{
8
  //enable pin change interrupts 4 and 5 (correspond to DIO2 and DIO3)
9
  //to trigger on both edges
10
  cli();
11
  EICRB = _BV(ISC40) | _BV(ISC50);
12
	EIMSK = _BV(INT4) | _BV(INT5);
13
  sei();
14
  
15
  //enable the 5V switching regulator to power the encoders
16
  DDRB |= _BV(PB4);
17
  PORTB &= ~_BV(PB4);
18

  
19
}
20

  
21
void encoders_reset (void)
22
{
23
  SYNC
24
  {
25
    count_l = 0;
26
    count_r = 0;
27
  }
28
}
29

  
30
ISR(INT4_vect)
31
{
32
  uint8_t temp = PINE;
33
  
34
  if(((temp&_BV(PE4))>>2)^(temp&_BV(PE2)))
35
    count_l--;
36
  else
37
    count_l++;
38
}
39

  
40
ISR(INT5_vect)
41
{
42
  uint8_t temp = PINE;
43
  
44
  if(((temp&_BV(PE5))>>2)^(temp&_BV(PE3)))
45
    count_r++;
46
  else
47
    count_r--;
48
}
49

  
50

  
51
void encoders_read (int16_t *values)
52
{
53
	usb_puts ("# Reading encoder values");
54
  SYNC
55
  {
56
	*values = count_l;
57
  *(values+1) = count_r;
58
  }
59
}
60

  
trunk/code/projects/diagnostic_station/station/comm_server.c
1 1
#include "comm_server.h"
2
#include "global.h"
3 2

  
4 3
#include <avr/pgmspace.h>
5 4

  
5
#include "global.h"
6

  
7
// ##############
8
// ## Settings ##
9
// ##############
10

  
11
#define comm_server_debug
12

  
13
// ###############
14
// ## Constants ##
15
// ###############
16

  
6 17
#define buffer_size 120
7 18

  
8 19

  
20
// ####################
21
// ## Initialization ##
22
// ####################
23

  
9 24
void comm_server_init ()
10 25
{
11 26
	usb_init ();
12
	
13 27
}
14 28

  
15
void server_send_finished ()
16
{
17
	usb_puts ("finished");
18
}
19 29

  
20
// Put all symbolic string constants into the program memory because else they would be copied into the RAM (see the
21
// avrlibc documentation).
22
const char command_ping          [] PROGMEM = "ping";
30
// ########################
31
// ## Message processing ##
32
// ########################
23 33

  
34
// This function is copied from XNS
35
//static void serial_send_string_P (const char *s)/*{{{*/
36
//{
37
//    char buf;
38
//    while (memcpy_P (&buf, s, sizeof (char)), buf!=0)
39
//    {
40
//        serial_transmit (buf);
41
//        s++;
42
//    }
43
//}
44

  
45

  
46

  
24 47
/** Check if the buffer starts with the given text, followed by a space */
48
// This function is copied from XNS
25 49
static bool serial_match (PGM_P text, uint8_t *buffer, uint8_t size)
26 50
{
27
	return false; // FIXME implement
28
//	uint8_t text_len=strlen_P (text);
51
	uint8_t text_len=strlen_P (text);
29 52

  
30 53
	// If the buffer is shorter than the text, there is no match
31
//	if (size<text_len) return false;
54
	if (size<text_len) return false;
32 55

  
33 56
	// If the buffer is longer than the text, it must have a space at position after the text
34
//	if (size>text_len && text[text_len]
57
	if (size>text_len && text[text_len]!=' ') return false;
35 58

  
59
	// Test for match
60
	if (strncmp_P ((char *)buffer, text, text_len)==0) return true;
61
	
62
	return false;
63
}
36 64

  
37
//	if ((equal_len || (longer && space after)) 
38
//&& strncmp_P
39
//            (serial_recieve_buffer, text, text_len)==0)
40 65

  
41
	
42 66

  
43
//	if ((size==text_len ||
44
//                (serial_recieve_buffer_len>text_len &&
45
//                 serial_recieve_buffer[text_len]==' ')) && strncmp_P
46
//            (serial_recieve_buffer, text, text_len)==0)
47
//    {
48
//        parameter_start=0;
49
//        parameter_length=text_len;
50
//        return true;
51
//    }
52
//    else
53
//    {
54
//        return false;
55
//    }
67

  
68
// ########################
69
// ## Messages (sending) ##
70
// ########################
71

  
72
void server_send_finished ()
73
{
74
	usb_puts ("finished");
56 75
}
57 76

  
58 77

  
78
// ##########################
79
// ## Messages (receiving) ##
80
// ##########################
81

  
82
// Put all symbolic string constants into the program memory because else all of them would be copied into the RAM (see
83
// the avr-libc documentation, chapter "Data in Program Space").
84
const char command_ping          [] PROGMEM = "ping";
85

  
59 86
static void handle_message (uint8_t *message, uint8_t size)
60 87
{
61
	usb_puts ("Received a message, size ");
88
#ifdef comm_server_debug
89
	usb_puts ("# Received a message, size ");
62 90
	usb_puti(size);
63
	usb_puts (": ");
64

  
65
	for (uint8_t i=0; i<size; ++i)
66
	{
67
		usb_putc (message[i]);
68
	}
91
	usb_puts (": [");
92
	usb_puts ((char *)message);
93
	usb_puts ("]" NL);
94
#endif
69 95
	
70
	usb_puts (NL);
96
	if (serial_match (command_ping, message, size)) usb_puts ("pong" NL);
71 97
}
72 98

  
73 99

  
74 100

  
75
// From XNS
76
//
77
//static void serial_send_string_P (const char *s)/*{{{*/
78
//{
79
//    char buf;
80
//    while (memcpy_P (&buf, s, sizeof (char)), buf!=0)
81
//    {
82
//        serial_transmit (buf);
83
//        s++;
84
//    }
85
//}
86 101

  
87

  
88

  
89 102
void byte_transmission_test (void)
90 103
{
91 104
	uint8_t c;
......
113 126
	{
114 127
		// Do nothing until we receive a byte (this function will return 0 when a character has been read)
115 128
		// (Yes, we could use the blocking function for now, but we may need the non-blocking later)
116
		while (usb_getc_nb (&c));
129
		while (usb_getc_nb ((char *)&c));
117 130
		
118 131
		if (c=='\r' || c=='\n')
119 132
		{
trunk/code/projects/diagnostic_station/station/hardware_rbom.h
1
#ifndef _hardware_rbom_h
2
#define _hardware_rbom_h
3

  
4
#include <dragonfly_lib.h>
5
#include "global.h"
6

  
7
void rbom_init (void);
8

  
9
void rbom_set (bool on);
10
uint16_t rbom_read (uint8_t value);
11
void rbom_update (void);
12

  
13

  
14
#endif
trunk/code/projects/diagnostic_station/station/hardware_wall.h
1
#ifndef _hardware_wall_h
2
#define _hardware_wall_h
3

  
4
#include <dragonfly_lib.h>
5
#include "global.h"
6

  
7

  
8
void wall_init (void);
9

  
10
void wall_set_position (uint16_t position);
11
uint16_t wall_get_position (void);
12

  
13

  
14
#endif
trunk/code/projects/diagnostic_station/station/hardware_encoders.h
1
#ifndef _hardware_encoders_h
2
#define _hardware_encoders_h
3

  
4
#include <dragonfly_lib.h>
5
#include "global.h"
6

  
7
void encoders_init (void);
8

  
9
void encoders_read (int16_t *values);
10
void encoders_reset (void);
11

  
12
#endif

Also available in: Unified diff