Laboratoire de CAN du cours SOI
Revision 1:48351dcae5b4, committed 2013-12-15
- Comitter:
- annicksenecal
- Date:
- Sun Dec 15 15:46:51 2013 +0000
- Parent:
- 0:fead003a74cb
- Child:
- 2:cad8d2ec9667
- Commit message:
- Programme final ? remettre
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Dec 13 21:10:33 2013 +0000
+++ b/main.cpp Sun Dec 15 15:46:51 2013 +0000
@@ -1,34 +1,80 @@
#include "mbed.h"
+#include "rtos.h"
-
-Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(p9, p10);
CAN can2(p30, p29);
-char counter = 0;
-
-void send() {
- printf("send()\n");
- if(can1.write(CANMessage(1337, &counter, 1))) {
- printf("wloop()\n");
- counter++;
- printf("Message sent: %d\n", counter);
- }
- led1 = !led1;
-}
-
-int main() {
- printf("main()\n");
- ticker.attach(&send, 1);
- CANMessage msg;
+
+
+void sendCan1(void const *args)
+{
+
+ char counter1 = 80;
+
while(1) {
- printf("loop()\n");
- if(can2.read(msg)) {
- printf("Message received: %d\n", msg.data[0]);
- led2 = !led2;
- }
- wait(0.2);
+
+
+ printf("send()\n");
+ if(can1.write(CANMessage(0x0480, &counter1, 1))) {
+ printf("wloop()\n");
+
+ printf("Message sent: %d\n", counter1);
+ counter1++;
+ }
+ if (counter1 >89) {
+ counter1 = 80;
+ }
+ led1 = !led1;
+ Thread::wait(1842);
}
}
+void sendCan2(void const *args)
+{
+
+ char counter2 = 180;
+
+ while(1) {
+ printf("send()\n");
+ if(can1.write(CANMessage(0x0580,&counter2,1))) {
+ printf("wloop()\n");
+
+ printf("Message sent: %d\n", counter2);
+ counter2++;
+ }
+ if (counter2 >189) {
+ counter2 = 180;
+ }
+ led1 = !led1;
+ Thread::wait(2351);
+ }
+}
+
+void receptionMsg(void const *args)
+{
+
+ CANMessage msg;
+
+ while(1) {
+ printf("reception()\n");
+ if(can2.read(msg))
+ printf("Message received: %x\n", msg.id);
+ if (msg.id == 1234)
+ printf("Message received: %d\n", msg.data[0]);
+ Thread::wait(958);
+ led2 = !led2;
+ }
+}
+
+int main()
+{
+
+ printf("main()\n");
+
+ Thread thread1(sendCan1);
+ Thread thread2(sendCan2);
+ Thread thread3(receptionMsg);
+ while(true);
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sun Dec 15 15:46:51 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f