Commit a29bfd4942fa9a88eda2c4f5e61d1dd479b47ffc

Authored by grouille
1 parent d3e704f6

MAJ Git

site/fichiersRPI/Build/Makefile
... ... @@ -3,27 +3,35 @@ export CC = avr-gcc
3 3 export MCU = atmega328p
4 4 export TARGET_ARCH = -mmcu=$(MCU)
5 5  
6   -export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g
  6 +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-pedantic -std=c99#-g
7 7 export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os
8 8  
9   -
10   -TARGET = blink
  9 +TARGET = libretour
  10 +TERM0 = /dev/ttyACM0
  11 +TERM1 = /dev/ttyACM1
11 12 CPPFLAGS = -mmcu=$(MCU)
12   -PGMERISP = -c pi_3
13   -ARVDUDECONF= -C ~/avrdude_gpio.conf
14   -export DUDE = avrdude -v -p $(MCU) $(AVRDUDECONF)
15   -
  13 +#PGMER = -c stk500v1 -b 57600 -P $(TERM)
  14 +#Dans le cas de l'upload par USB (selon le port)
  15 +PGMERISP0 = -c stk500v1 -b 115200 -P $(TERM0)
  16 +PGMERISP1 = -c stk500v1 -b 115200 -P $(TERM1)
  17 +ARVDUDECONF= -C /usr/local/arduino/arduino-0021/hardware/tools/avrdude.conf
  18 +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF)
  19 +#Dans le cas de l'upload par SPI depuis la raspberry
  20 +PGMERISP_RPI = -c pi_3
  21 +ARVDUDECONF_RPI = -C ~/avrdude_gpio.conf
  22 +export DUDE_RPI = avrdude -v -p $(MCU) $(AVRDUDECONF_RPI)
  23 +
  24 +CLIB=ar cq
16 25 C_SRC = $(wildcard *.c)
17 26 OBJS = $(C_SRC:.c=.o)
18 27  
19   -
20   -all: $(TARGET).hex
  28 +all: $(TARGET).a
21 29  
22 30  
23 31 clean:
24   - rm -f *.o *.hex *.elf build-uno
  32 + rm -f *.o *.hex *.elf *.a build-uno
25 33  
26   -%.o:%.c
  34 +$(TARGET).o: $(TARGET).c $(TARGET).h
27 35 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
28 36  
29 37  
... ... @@ -34,8 +42,46 @@ $(TARGET).hex: $(TARGET).elf
34 42 avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
35 43 avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex
36 44  
  45 +$(TARGET).a: $(TARGET).o
  46 + rm -rf $@
  47 + $(CLIB) $@ $+
  48 +
  49 +
  50 +#UPLOAD CONDITIONNEL
  51 +FOLDER = $(notdir $(CURDIR))
  52 +
37 53 upload: $(TARGET).hex
38   - $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex
  54 +#CAPTEUR 1 connecté en USB
  55 +ifeq ($(FOLDER), capteur1-0)
  56 +
  57 + stty -F $(TERM0) hupcl # reset
  58 + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
  59 + $(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex
  60 +endif
  61 +
  62 +#CAPTEUR 1 connecté en SPI
  63 +ifeq ($(FOLDER), capteur1-1)
  64 +
  65 + stty -F $(TERM0) hupcl # reset
  66 + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
  67 + $(DUDE_RPI) $(PGMERISP_RPI) -U flash:w:$(TARGET).hex
  68 +endif
  69 +
  70 +#CAPTEUR 2 connecté en USB
  71 +ifeq ($(FOLDER), capteur2-0)
  72 +
  73 + stty -F $(TERM1) hupcl # reset
  74 + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
  75 + $(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex
  76 +endif
  77 +
  78 +#CAPTEUR 2 connecté en SPI
  79 +ifeq ($(FOLDER), capteur2-1)
  80 +
  81 + stty -F $(TERM1) hupcl # reset
  82 + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
  83 + $(DUDE_RPI) $(PGMERISP_RPI) -U flash:w:$(TARGET).hex
  84 +endif
39 85  
40 86 size: $(TARGET).elf
41 87 avr-size --format=avr --mcu=$(MCU) $(TARGET).elf
... ...
codes/Tuno_to_rpi.c renamed to site/fichiersRPI/Build/libretour/libretour.c
1   -#include <avr/io.h> // for the input/output register
2   -#include <avr/interrupt.h>
3   -#include <util/delay.h>
  1 +#include <avr/io.h>
  2 +#include <avr/interrupt.h>
  3 +#include <util/delay.h>
4 4 #include <string.h>
5   -#include <stdio.h>
6 5 #include <stdlib.h>
  6 +#include <stdio.h>
  7 +
  8 +
7 9 #define PRESCALER 1024
8 10 #define TIME_SLOT 20
9 11 #define BAUDRATE 103
10 12  
11   -#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
12   -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
13   -
14   -char Donnee[24];
15   -float temp;
  13 +//// INIT SERIAL /////
16 14  
17 15 void init_serial(void)
18 16 {
... ... @@ -22,14 +20,15 @@ void init_serial(void)
22 20 /* Set baud rate */
23 21 UBRR0H = 0;
24 22 UBRR0L = baudrate;
25   - /* Enable transmitter *///task_led_red();
26   - //task_send_serial('A');
  23 +
27 24 UCSR0B = (1<<TXEN0);
28 25 /* Set frame format */
29 26 UCSR0C = 0x06;
30 27  
31 28 }
32 29  
  30 +//// ENVOI DE MESSAGES /////
  31 +
33 32 void send_serial(unsigned char c)
34 33 {
35 34 loop_until_bit_is_set(UCSR0A, UDRE0);
... ... @@ -66,50 +65,9 @@ void send_msg(char Donnee[]){
66 65 }
67 66 }
68 67  
69   -
70   -// équivalent de analogueRead()
71   -int analogReadNew(uint8_t pin) {
72   - /*
73   - // Définition de la référence de tension
74   - ADMUX |= (1 << REFS0);
75   - // On sélectionne notre pin
76   - ADMUX |= pin & 0x07;
77   -
78   - // On lance la conversion
79   - sbi(ADCSRA, ADSC);
80   -
81   - // Le bit sera désactivé à la fin de la conversion
82   - while(bit_is_set(ADCSRA, ADSC));
83   -
84   - // Lire ADCL en premier est obligatoire, sinon l'ADC se bloque
85   - uint8_t low = ADCL;
86   -
87   - // Récupérer le résultat
88   - return ((ADCH << 8) | low);
89   - */
90   - ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
91   - ADMUX |= (1<<REFS0)|(1<<ADLAR);
92   - ADMUX = (ADMUX&0xf0)|pin;
93   - ADCSRA |= (1<<ADEN);
94   -
95   - ADCSRA |= (1<<ADSC);
96   - while(bit_is_set(ADCSRA, ADSC));
97   - return ADCH;
98   -}
99   -
100   -int main()
101   -{
102   - int reading;
103   - init_serial();
104   - while(1){
105   - reading=analogReadNew(0);
106   - temp = reading * 1.9607843;
107   - dtostrf(temp, 4, 1, Donnee);
108   - send_serial('T');
109   - send_serial('=');
110   - send_msg2(Donnee);
111   - _delay_ms(2000);
112   - }
113   - return 0;
  68 +//////// RETOUR /////////
  69 +void retour(char* show_a){
  70 + send_msg2(show_a);
114 71 }
115   -
  72 +
  73 +
... ...
site/fichiersRPI/Build/libretour/libretour.h 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +
  2 +
  3 +void init_serial(void);
  4 +
  5 +void send_serial(unsigned char);
  6 +
  7 +void send_msg2(char*);
  8 +
  9 +void send_msg(char*);
  10 +
  11 +void retour(char*);
  12 +
  13 +//////////////////////////////////////////////
  14 +
... ...
site/fichiersRPI/Build/main.c deleted
... ... @@ -1,114 +0,0 @@
1   -#include <avr/io.h> // for the input/output register
2   -#include <avr/interrupt.h>
3   -#include <util/delay.h>
4   -#include <string.h>
5   -#include <stdio.h>
6   -#include <stdlib.h>
7   -#define PRESCALER 1024
8   -#define TIME_SLOT 20
9   -#define BAUDRATE 103
10   -
11   -#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
12   -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
13   -
14   -char Donnee[24];
15   -float temp;
16   -
17   -void init_serial(void)
18   -{
19   - /* ACHTUNG : we suppose UBRR value < 0xff */
20   - /* Not true in all case */
21   - uint8_t baudrate = BAUDRATE;
22   - /* Set baud rate */
23   - UBRR0H = 0;
24   - UBRR0L = baudrate;
25   - /* Enable transmitter *///task_led_red();
26   - //task_send_serial('A');
27   - UCSR0B = (1<<TXEN0);
28   - /* Set frame format */
29   - UCSR0C = 0x06;
30   -
31   -}
32   -
33   -void send_serial(unsigned char c)
34   -{
35   - loop_until_bit_is_set(UCSR0A, UDRE0);
36   - UDR0 = c;
37   -}
38   -
39   -
40   -void send_msg2(char Donnee[]){
41   -
42   - while (( UCSR0A & (1<<UDRE0)) == 0){};
43   -
44   - for (int i = 0; i < strlen(Donnee); i++){
45   - while (( UCSR0A & (1<<UDRE0)) == 0){};
46   - UDR0 = Donnee[i];
47   - if (i == (strlen(Donnee) - 1)){
48   - send_serial('\n');
49   - send_serial('\r');
50   - }
51   - }
52   -}
53   -
54   -void send_msg(char Donnee[]){
55   - int i=0;
56   - for(i=0; i<strlen(Donnee); i++){
57   - if (i==strlen(Donnee)-1){
58   - send_serial(Donnee[i]);
59   - send_serial('\n');
60   - send_serial('\r');
61   - }
62   - else{
63   - send_serial(Donnee[i]);
64   - }
65   - _delay_ms(100);
66   - }
67   -}
68   -
69   -
70   -// équivalent de analogueRead()
71   -int analogReadNew(uint8_t pin) {
72   - /*
73   - // Définition de la référence de tension
74   - ADMUX |= (1 << REFS0);
75   - // On sélectionne notre pin
76   - ADMUX |= pin & 0x07;
77   -
78   - // On lance la conversion
79   - sbi(ADCSRA, ADSC);
80   -
81   - // Le bit sera désactivé à la fin de la conversion
82   - while(bit_is_set(ADCSRA, ADSC));
83   -
84   - // Lire ADCL en premier est obligatoire, sinon l'ADC se bloque
85   - uint8_t low = ADCL;
86   -
87   - // Récupérer le résultat
88   - return ((ADCH << 8) | low);
89   - */
90   - ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
91   - ADMUX |= (1<<REFS0)|(1<<ADLAR);
92   - ADMUX = (ADMUX&0xf0)|pin;
93   - ADCSRA |= (1<<ADEN);
94   -
95   - ADCSRA |= (1<<ADSC);
96   - while(bit_is_set(ADCSRA, ADSC));
97   - return ADCH;
98   -}
99   -
100   -int main()
101   -{
102   - int reading;
103   - init_serial();
104   - while(1){
105   - reading=analogReadNew(0);
106   - temp = reading * 1.9607843;
107   - dtostrf(temp, 4, 1, Donnee);
108   - //send_serial('T');
109   - //send_serial('=');
110   - send_msg2(Donnee);
111   - _delay_ms(2000);
112   - }
113   - return 0;
114   -}
site/fichiersRPI/script.sh
1 1 #!/bin/sh
  2 +
  3 +echo $$ > /var/run/script.pid
  4 +
2 5 ./load.sh
3 6 while true
4 7 do
... ...
site/fichiersRPI/toto.sh deleted
... ... @@ -1,3 +0,0 @@
1   -#!/bin/sh
2   -sudo su
3   -./script.sh