You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(50) |
Feb
(137) |
Mar
(84) |
Apr
(36) |
May
(100) |
Jun
(5) |
Jul
|
Aug
(4) |
Sep
(13) |
Oct
(1) |
Nov
(4) |
Dec
(22) |
2011 |
Jan
(4) |
Feb
(9) |
Mar
(113) |
Apr
(76) |
May
(31) |
Jun
(19) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
(4) |
Feb
|
Mar
(2) |
Apr
(6) |
May
(19) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(2) |
Apr
(22) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jérémie D. <Ba...@us...> - 2011-03-23 23:01:19
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via aad13dd94ac9a04ac7ce9baf72c2013a003ca3e5 (commit) via c4439e711ffccdfe67688a600531b6a51f11a60e (commit) from f3fa4458fe1d51ceed1a08dcc53d0a00e27135a0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit aad13dd94ac9a04ac7ce9baf72c2013a003ca3e5 Author: Jérémie Dimino <je...@di...> Date: Wed Mar 23 23:58:44 2011 +0100 [info] add krobot-dump-encoders for dumping values returned by encoders commit c4439e711ffccdfe67688a600531b6a51f11a60e Author: Jérémie Dimino <je...@di...> Date: Wed Mar 23 20:40:34 2011 +0100 [info] fix krobot-replay ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 45d3a1f..6c88cb8 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -77,6 +77,13 @@ Executable "krobot-dump" MainIs: krobot_dump.ml BuildDepends: krobot, lwt.syntax +Executable "krobot-dump-encoders" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_dump_encoders.ml + BuildDepends: krobot, lwt.syntax + Executable "krobot-record" Path: src/tools Install: true diff --git a/info/control2011/_tags b/info/control2011/_tags index a3008ee..0388686 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 38e202213a4e5cf93f993d106d81dd20) +# DO NOT EDIT (digest: 689823deb2ad1bb10042fed50bc857aa) # Library krobot-interfaces "src/interfaces": include <src/interfaces/*.ml{,i}>: pkg_obus @@ -31,6 +31,12 @@ <src/tools/krobot_dump.{native,byte}>: pkg_obus <src/tools/krobot_dump.{native,byte}>: pkg_lwt.unix <src/tools/krobot_dump.{native,byte}>: pkg_lwt.syntax +# Executable krobot-dump-encoders +<src/tools/krobot_dump_encoders.{native,byte}>: use_krobot +<src/tools/krobot_dump_encoders.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_obus +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_lwt.syntax # Executable krobot-driver <src/driver/krobot_driver.{native,byte}>: use_krobot-can <src/driver/krobot_driver.{native,byte}>: use_krobot diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index f47197f..8f530a8 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 8409a4ff28b50b5fc83795c40aa4d4a1) *) +(* DO NOT EDIT (digest: 0af52517b361f6b2a84eef09e15eb0d2) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5190,6 +5190,36 @@ let setup_t = src_repo_tag = None; src_repo_subdir = None; }); + Executable + ({ + cs_name = "krobot-dump-encoders"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + { + exec_custom = false; + exec_main_is = "krobot_dump_encoders.ml"; + }); Doc ({ cs_name = "krobot-api"; diff --git a/info/control2011/src/tools/krobot_dump_encoders.ml b/info/control2011/src/tools/krobot_dump_encoders.ml new file mode 100644 index 0000000..0d18d7a --- /dev/null +++ b/info/control2011/src/tools/krobot_dump_encoders.ml @@ -0,0 +1,36 @@ +(* + * krobot_dump_encoders.ml + * ----------------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* Dump values of encoders into files. *) + +open Lwt +open Lwt_react +open Krobot_message + +lwt () = + lwt bus = Krobot_bus.get () in + + lwt oc1 = Lwt_io.open_file ~mode:Lwt_io.output "krobot1.dump" + and oc2 = Lwt_io.open_file ~mode:Lwt_io.output "krobot2.dump" in + + E.keep + (E.map_s + (fun (timestamp, msg) -> + match msg with + | Encoder_position_speed_3(pos, speed) -> + Lwt_io.fprintlf oc1 "%f %f %f" timestamp pos speed + | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> + Lwt_io.fprintlf oc2 "%f %d %d" timestamp pos3 (match dir3 with Forward -> 0 | Backward -> 1) + | _ -> + return ()) + (Krobot_message.recv bus)); + + lwt () = Lwt_io.printl "press Enter to exit." in + lwt _ = Lwt_io.read_line Lwt_io.stdin in + return () diff --git a/info/control2011/src/tools/krobot_replay.ml b/info/control2011/src/tools/krobot_replay.ml index 3ec07e7..82a62e8 100644 --- a/info/control2011/src/tools/krobot_replay.ml +++ b/info/control2011/src/tools/krobot_replay.ml @@ -12,11 +12,11 @@ open Lwt open Lwt_react -let rec loop bus ic delta prev_timestamp = +let rec loop bus ic prev_timestamp = lwt timestamp, frame = Lwt_io.read_value ic in lwt () = Lwt_unix.sleep (timestamp -. prev_timestamp) in - lwt () = Krobot_can.send bus (timestamp +. delta, frame) in - loop bus ic delta timestamp + lwt () = Krobot_can.send bus (Unix.gettimeofday (), frame) in + loop bus ic timestamp lwt () = if Array.length Sys.argv <> 2 then begin @@ -28,11 +28,8 @@ lwt () = lwt ic = Lwt_io.open_file ~mode:Lwt_io.input Sys.argv.(1) in try_lwt - (* Read the first frame. *) lwt timestamp, frame = Lwt_io.read_value ic in - (* Compute the difference of time to add to each timestamp. *) - let delta = Unix.gettimeofday () -. timestamp in - lwt () = Krobot_can.send bus (timestamp +. delta, frame) in - loop bus ic delta timestamp + lwt () = Krobot_can.send bus (Unix.gettimeofday (), frame) in + loop bus ic timestamp with End_of_file -> Lwt_io.close ic hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-23 22:29:22
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via f3fa4458fe1d51ceed1a08dcc53d0a00e27135a0 (commit) from 8c0f5ac64c3ecc067a77863f07fa7b933d8d67a5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f3fa4458fe1d51ceed1a08dcc53d0a00e27135a0 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 23 23:28:15 2011 +0100 [Controller_Motor_STM32] can_monitor : Boulet Time. Fixed a bug where estimated speed and position were not readable in CAN messages ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c index f853175..dca6596 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c @@ -28,7 +28,7 @@ typedef union { uint32_t data32[2]; } encoder_can_msg_t; -typedef struct { +typedef union { motor_msg_t data; uint32_t data32[2]; } motor_can_msg_t; @@ -95,8 +95,8 @@ static void NORETURN canMonitor_process(void) { msg_mot.data.position = mc_getPosition(MOTOR4); msg_mot.data.speed = mc_getSpeed(MOTOR4); - txm.data32[0] = (int32_t)mc_getPosition(MOTOR4);//msg_mot.data32[0]; - txm.data32[1] = (int32_t)mc_getSpeed(MOTOR4);//msg_mot.data32[1]; + txm.data32[0] = msg_mot.data32[0]; + txm.data32[1] = msg_mot.data32[1]; txm.eid = 102; can_transmit(CAND1, &txm, ms_to_ticks(10)); hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-23 19:37:36
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 8c0f5ac64c3ecc067a77863f07fa7b933d8d67a5 (commit) from b4e5a277a43da0fceaf3b05384e6db6f07d43865 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 8c0f5ac64c3ecc067a77863f07fa7b933d8d67a5 Author: Jérémie Dimino <je...@di...> Date: Wed Mar 23 20:32:28 2011 +0100 [info] typo in krobot-record ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/tools/krobot_record.ml b/info/control2011/src/tools/krobot_record.ml index 6b7a466..f0a7d72 100644 --- a/info/control2011/src/tools/krobot_record.ml +++ b/info/control2011/src/tools/krobot_record.ml @@ -22,7 +22,7 @@ lwt () = lwt oc = Lwt_io.open_file ~mode:Lwt_io.output Sys.argv.(1) in (* The proxy for the driver. *) - let driver = OBus_proxy.make (OBus_peer.make (Krobot_bus.to_bus bus) "fr.krobot.Driver") ["fr"; "krobot"; "CAN"] in + let driver = OBus_proxy.make (OBus_peer.make (Krobot_bus.to_bus bus) "fr.krobot.Service.Driver") ["fr"; "krobot"; "CAN"] in (* Receive frames comming from the driver. *) lwt ev = OBus_signal.connect (OBus_signal.make Krobot_interface_can.Fr_krobot_CAN.s_message driver) in hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-23 19:26:45
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via b4e5a277a43da0fceaf3b05384e6db6f07d43865 (commit) from 7c145a8bcb0fa1400dbe1344b84efd887941a4ff (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b4e5a277a43da0fceaf3b05384e6db6f07d43865 Author: Jérémie Dimino <je...@di...> Date: Wed Mar 23 20:25:53 2011 +0100 [info] typo in the message printer ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 5536716..121d531 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -46,7 +46,7 @@ let to_string = function "Encoder_position_speed_4(%f, %f)" pos speed | Unknown frame -> - Krobot_can.string_of_frame frame + sprintf "Unknown%s" (Krobot_can.string_of_frame frame) (* +-----------------------------------------------------------------+ | Encoding | hooks/post-receive -- krobot |
From: Nicolas D. <Ba...@us...> - 2011-03-22 18:06:10
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 7c145a8bcb0fa1400dbe1344b84efd887941a4ff (commit) from 4e7bbded87fc3ae7a0741dbc9abfda6e01c12f6a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7c145a8bcb0fa1400dbe1344b84efd887941a4ff Author: Nicolas Dandrimont <Nic...@cr...> Date: Tue Mar 22 19:02:50 2011 +0100 [USB_CAN/Firmware] Allow a configurable timestamping function ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c index ef58b89..75d3c4a 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c @@ -45,12 +45,19 @@ INLINE uint32_t nibble_to_uint32(char *nibbles, size_t length) { return ret; } +uint16_t get_timestamp(void) { + /* The timestamp should wrap around every minute (it works until + the 32 bits of timer_clock are exhausted) */ + return ticks_to_ms(timer_clock()) % 60000; +} + void usb_can_init(usb_can *usbcan, can_driver *can, struct Serial *ser) { usbcan->can = can; usbcan->ser = ser; usbcan->is_open = false; usbcan->timestamped = false; + usbcan->get_timestamp = get_timestamp; } @@ -195,9 +202,7 @@ int usb_can_emit(usb_can *usbcan, can_rx_frame *frame) { sprintf(&buffer[i], "%02x", frame->data8[j]); if (usbcan->timestamped) { - /* The timestamp should wrap around every minute (it works until - the 32 bits of timer_clock are exhausted) */ - timestamp = ticks_to_ms(timer_clock()) % 60000; + timestamp = usbcan->get_timestamp(); sprintf(&buffer[i], "%04x", timestamp); i+=4; diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h index 960f819..800e4a5 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h @@ -31,13 +31,18 @@ #include <drv/timer.h> #include <io/kfile.h> +typedef uint16_t (usb_can_timestamp(void)); + typedef struct _usb_can { can_driver *can; // CAN Device struct Serial *ser; // Serial Device bool is_open; // Channel open? bool timestamped; // Emit timestamps? + usb_can_timestamp *get_timestamp; // Get Timestamp function } usb_can; +uint16_t get_timestamp(void); + void usb_can_init(usb_can *usbcan, can_driver *can, struct Serial *ser); void usb_can_open(usb_can *usbcan); hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-21 09:27:46
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 4e7bbded87fc3ae7a0741dbc9abfda6e01c12f6a (commit) from a414b505a146c51f221aaa54266e42584d4ebc33 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4e7bbded87fc3ae7a0741dbc9abfda6e01c12f6a Author: Jérémie Dimino <je...@di...> Date: Mon Mar 21 10:27:13 2011 +0100 [info] add the krobot-viewer tool ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 3d6033b..45d3a1f 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -112,6 +112,12 @@ Executable "krobot-plot" MainIs: krobot_plot.ml BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads +Executable "krobot-viewer" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_viewer.ml + BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads, lablgtk2.glade # +-------------------------------------------------------------------+ # | Examples | diff --git a/info/control2011/_tags b/info/control2011/_tags index c48d120..a3008ee 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 3f2673f16efc8fd23f421702ae380100) +# DO NOT EDIT (digest: 38e202213a4e5cf93f993d106d81dd20) # Library krobot-interfaces "src/interfaces": include <src/interfaces/*.ml{,i}>: pkg_obus @@ -44,6 +44,17 @@ <src/driver/*.ml{,i}>: pkg_obus <src/driver/*.ml{,i}>: pkg_lwt.unix <src/driver/*.ml{,i}>: pkg_lwt.syntax +# Executable krobot-viewer +<src/tools/krobot_viewer.{native,byte}>: use_krobot +<src/tools/krobot_viewer.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_viewer.{native,byte}>: pkg_threads +<src/tools/krobot_viewer.{native,byte}>: pkg_obus +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.glib +<src/tools/krobot_viewer.{native,byte}>: pkg_lablgtk2.glade +<src/tools/krobot_viewer.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/*.ml{,i}>: pkg_lablgtk2.glade # Executable krobot-remote <src/tools/krobot_remote.{native,byte}>: use_krobot <src/tools/krobot_remote.{native,byte}>: use_krobot-interfaces diff --git a/info/control2011/myocamlbuild.ml b/info/control2011/myocamlbuild.ml index 5037c7d..08cc900 100644 --- a/info/control2011/myocamlbuild.ml +++ b/info/control2011/myocamlbuild.ml @@ -479,7 +479,11 @@ let () = | After_rules -> rule "D-Bus interface generation: .obus -> .ml, .mli" ~dep:"%.obus" ~prods:["%.ml"; "%.mli"] - (fun env _ -> Cmd(S[A"obus-gen-interface"; A"-o"; A(env "%"); A(env "%.obus")])) + (fun env _ -> Cmd(S[A"obus-gen-interface"; A"-o"; A(env "%"); A(env "%.obus")])); + + rule ".glade -> .ml" ~dep:"%.glade" ~prod:"%.ml" + (fun env _ -> + Cmd(S[A"lablgladecc2"; A"-embed"; A(env "%.glade"); Sh">"; A(env "%.ml")])) | _ -> ()) diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index b2af3c8..f47197f 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,9 +1,9 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 80867cfdd6884c39f5a6799ecb9f747d) *) +(* DO NOT EDIT (digest: 8409a4ff28b50b5fc83795c40aa4d4a1) *) (* - Regenerated by OASIS v0.2.0~alpha1 + Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and documentation about functions used in this file. *) @@ -5243,6 +5243,37 @@ let setup_t = {exec_custom = false; exec_main_is = "krobot_driver.ml"; }); Executable ({ + cs_name = "krobot-viewer"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None); + FindlibPackage ("cairo.lablgtk2", None); + FindlibPackage ("lwt.glib", None); + FindlibPackage ("threads", None); + FindlibPackage ("lablgtk2.glade", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + {exec_custom = false; exec_main_is = "krobot_viewer.ml"; }); + Executable + ({ cs_name = "krobot-remote"; cs_data = PropList.Data.create (); cs_plugin_data = []; @@ -5412,7 +5443,7 @@ let setup_t = schema_data = PropList.Data.create (); plugin_data = []; }; - version = "0.2.0~alpha1"; + version = "0.2.0"; };; let setup () = BaseSetup.setup setup_t;; diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml new file mode 100644 index 0000000..b66383d --- /dev/null +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -0,0 +1,392 @@ +(* + * krobot_viewer.ml + * ---------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +open Lwt +open Lwt_react + +let utf8 code = + let set_byte s o x = String.unsafe_set s o (Char.unsafe_chr x) in + if code < 0x80 then begin + let s = String.create 1 in + set_byte s 0 code; + s + end else if code <= 0x800 then begin + let s = String.create 2 in + set_byte s 0 ((code lsr 6) lor 0xc0); + set_byte s 1 ((code land 0x3f) lor 0x80); + s + end else if code <= 0x10000 then begin + let s = String.create 3 in + set_byte s 0 ((code lsr 12) lor 0xe0); + set_byte s 1 (((code lsr 6) land 0x3f) lor 0x80); + set_byte s 2 ((code land 0x3f) lor 0x80); + s + end else if code <= 0x10ffff then begin + let s = String.create 4 in + set_byte s 0 ((code lsr 18) lor 0xf0); + set_byte s 1 (((code lsr 12) land 0x3f) lor 0x80); + set_byte s 2 (((code lsr 6) land 0x3f) lor 0x80); + set_byte s 3 ((code land 0x3f) lor 0x80); + s + end else + invalid_arg "utf8" + +(* +-----------------------------------------------------------------+ + | LCD | + +-----------------------------------------------------------------+ *) + +module LCD = struct + type t = { + chars : char array array; + mutable line : int; + mutable column : int; + mutable cursor : bool; + mutable backlight : bool; + } + + let lines = 3 + let columns = 20 + let inter = 4. + let border = 2. + + let create () = { + chars = Array.make_matrix lines columns ' '; + line = 0; + column = 0; + cursor = true; + backlight = true; + } + + type colors = { + background : float * float * float; + text_background : float * float * float; + text_foreground : float * float * float; + } + + let colors_light = { + background = (0.4, 0.4, 1.0); + text_background = (0.0, 0.0, 0.7); + text_foreground = (1.0, 1.0, 1.0); + } + + let colors_dark = { + background = (0.1, 0.1, 0.25); + text_background = (0.0, 0.0, 0.7 /. 4.); + text_foreground = (0.25, 0.25, 0.25); + } + + let set_color ctx (r, g, b) = + Cairo.set_source_rgb ctx r g b + + let draw widget lcd = + let colors = if lcd.backlight then colors_light else colors_dark in + let { Gtk.width; Gtk.height } = widget#misc#allocation in + let surface = Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in + let ctx = Cairo.create surface in + Cairo.select_font_face ctx "Monospace" Cairo.FONT_SLANT_NORMAL Cairo.FONT_WEIGHT_NORMAL; + Cairo.set_font_size ctx 20.; + set_color ctx colors.background; + Cairo.rectangle ctx 0. 0. (float width) (float height); + Cairo.fill ctx; + let { Cairo.max_x_advance = fw; + Cairo.font_height = fh; + Cairo.descent = descent } = Cairo.font_extents ctx in + for line = 0 to lines - 1 do + for column = 0 to columns - 1 do + let x = inter +. (fw +. inter +. border *. 2.0) *. float column + and y = inter +. (fh +. inter +. border *. 2.0) *. float line in + set_color ctx colors.text_background; + Cairo.rectangle ctx x y (fw +. border *. 2.0) (fh +. border *. 2.0); + Cairo.fill ctx; + Cairo.move_to ctx (x +. border) (y +. fh -. descent +. border); + set_color ctx colors.text_foreground; + Cairo.show_text ctx (utf8 (Char.code lcd.chars.(line).(column))) + done + done; + if lcd.cursor then begin + let x = inter +. (fw +. inter +. border *. 2.0) *. float lcd.column + and y = inter +. (fh +. inter +. border *. 2.0) *. float lcd.line in + set_color ctx colors.text_foreground; + Cairo.rectangle ctx x y (fw +. border *. 2.0) (fh +. border *. 2.0); + Cairo.fill ctx + end; + let ctx = Cairo_lablgtk.create widget#misc#window in + Cairo.set_source_surface ctx surface 0. 0.; + Cairo.rectangle ctx 0. 0. (float width) (float height); + Cairo.fill ctx; + Cairo.surface_finish surface + + let add_char lcd ch = + lcd.chars.(lcd.line).(lcd.column) <- ch; + if lcd.column + 1 < columns then + lcd.column <- lcd.column + 1 + else if lcd.line + 1 < lines then begin + lcd.line <- lcd.line + 1; + lcd.column <- 0 + end else begin + lcd.line <- 0; + lcd.column <- 0 + end + + let clear lcd = + Array.iter (fun line -> Array.fill line 0 columns ' ') lcd.chars; + lcd.column <- 0; + lcd.line <- 0 + + let set_cursor lcd state = + lcd.cursor <- state + + let set_backlight lcd state = + lcd.backlight <- state + + let goto lcd line column = + lcd.line <- line mod lines; + lcd.column <- column mod columns + + let write lcd text = + String.iter (add_char lcd) text + + let write_line lcd ~line ~text = + lcd.line <- line mod lines; + lcd.column <- 0; + write lcd text +end + +(* +-----------------------------------------------------------------+ + | The board | + +-----------------------------------------------------------------+ *) + +module Board = struct + type state = { + x : float; + y : float; + theta : float; + } + + type t = { + mutable state : state; + } + + let world_height = 2.1 + let world_width = 3. + let robot_size = 0.3 + let wheels_diam = 0.098 + let wheels_dist = 0.259 + let sim_step = 0.01 + let time = ref 0. + + type color = + | Black + | White + | Green + | Red + | Blue + | Yellow + + let set_color ctx color = + let r, g, b = match color with + | Black -> (0., 0., 0.) + | White -> (255., 255., 255.) + | Green -> (36., 145., 64.) + | Red -> (199., 23., 18.) + | Blue -> (0., 59., 128.) + | Yellow -> (252., 189., 31.) + in + Cairo.set_source_rgb ctx (r /. 255.) (g /. 255.) (b /. 255.) + + let pi = 4. *. atan 1. + + let draw widget board = + let { Gtk.width; Gtk.height } = widget#misc#allocation in + let surface = Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in + let ctx = Cairo.create surface in + let width = float width and height = float height in + + (* Draw the background *) + Cairo.rectangle ctx 0. 0. width height; + set_color ctx White; + Cairo.fill ctx; + + (* Compute the optimal width and height *) + let dw, dh = + if width /. height >= (world_width +. 0.204) /. (world_height +. 0.204) then + ((world_width +. 0.204) /. (world_height +. 0.204) *. height, height) + else + (width, width /. (world_width +. 0.204) *. (world_height +. 0.204)) + in + + (* Translation to have the board at the center and scaling to match the window sizes *) + let x0 = (width -. dw) /. 2. and y0 = (height -. dh) /. 2. in + let scale = dw /. (world_width +. 0.204) in + Cairo.translate ctx (x0 +. 0.102 *. scale) (y0 +. dh -. 0.102 *. scale); + Cairo.scale ctx scale (-.scale); + + Cairo.set_line_width ctx (1. /. scale); + + (* Draw the borders *) + Cairo.rectangle ctx (-0.022) (-0.022) (world_width +. 0.044) (world_height +. 0.044); + set_color ctx Black; + Cairo.fill ctx; + + (* Draw beacon supports *) + Cairo.rectangle ctx (-0.102) (-0.102) 0.08 0.08; + Cairo.fill ctx; + + Cairo.rectangle ctx (-0.102) (world_height /. 2. -. 0.04) 0.08 0.08; + Cairo.fill ctx; + + Cairo.rectangle ctx (-0.102) (world_height +. 0.022) 0.08 0.08; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width +. 0.022) (-0.102) 0.08 0.08; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width +. 0.022) (world_height /. 2. -. 0.04) 0.08 0.08; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width +. 0.022) (world_height +. 0.022) 0.08 0.08; + Cairo.fill ctx; + + (* Draw the board background *) + Cairo.rectangle ctx 0. 0. world_width world_height; + set_color ctx Green; + Cairo.fill ctx; + + (* Draw the starting areas *) + Cairo.rectangle ctx 0. (world_height -. 0.4) 0.4 0.4; + set_color ctx Red; + Cairo.fill ctx; + Cairo.rectangle ctx (world_width -. 0.4) (world_height -. 0.4) 0.4 0.4; + set_color ctx Blue; + Cairo.fill ctx; + + (* Draw the paving *) + for i = 0 to 5 do + for j = 0 to 5 do + let x = 0.45 +. 0.35 *. float i + and y = 0.35 *. float j in + Cairo.rectangle ctx x y 0.35 0.35; + set_color ctx (if (i + j) mod 2 = 0 then Red else Blue); + Cairo.fill ctx + done + done; + + (* Draw the bands *) + set_color ctx Black; + + Cairo.rectangle ctx 0.4 0. 0.05 world_height; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 0.45) 0. 0.05 world_height; + Cairo.fill ctx; + + Cairo.rectangle ctx 0.45 0.33 0.7 0.02; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 1.15) 0.33 0.7 0.02; + Cairo.fill ctx; + + Cairo.rectangle ctx 1.13 0. 0.02 0.35; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 1.15) 0. 0.02 0.35; + Cairo.fill ctx; + + Cairo.rectangle ctx 0.45 0. 0.7 0.12; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 1.15) 0. 0.7 0.12; + Cairo.fill ctx; + + Cairo.rectangle ctx 0.45 0. 0.02 0.25; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 0.47) 0. 0.02 0.25; + Cairo.fill ctx; + + Cairo.move_to ctx 0. (world_height -. 0.4); + Cairo.rel_line_to ctx 0.4 0.; + Cairo.stroke ctx; + + Cairo.move_to ctx 0. (world_height -. 0.422); + Cairo.rel_line_to ctx 0.4 0.; + Cairo.stroke ctx; + + Cairo.move_to ctx (world_width -. 0.4) (world_height -. 0.4); + Cairo.rel_line_to ctx 0.4 0.; + Cairo.stroke ctx; + + Cairo.move_to ctx (world_width -. 0.4) (world_height -. 0.422); + Cairo.rel_line_to ctx 0.4 0.; + Cairo.stroke ctx; + + (* Draw circles on bonus cases *) + Cairo.arc ctx 0.975 0.875 0.05 0. (2. *. pi); + Cairo.fill ctx; + + Cairo.arc ctx 0.975 1.575 0.05 0. (2. *. pi); + Cairo.fill ctx; + + Cairo.arc ctx 2.025 0.875 0.05 0. (2. *. pi); + Cairo.fill ctx; + + Cairo.arc ctx 2.025 1.575 0.05 0. (2. *. pi); + Cairo.fill ctx; + + Cairo.arc ctx 1.325 0.175 0.05 0. (2. *. pi); + Cairo.fill ctx; + + Cairo.arc ctx 1.675 0.175 0.05 0. (2. *. pi); + Cairo.fill ctx; + + (* Draw the robot *) + Cairo.translate ctx board.state.x board.state.y; + Cairo.rotate ctx board.state.theta; + Cairo.rectangle ctx (-. robot_size /. 2.) (-. robot_size /. 2.) robot_size robot_size; + set_color ctx White; + Cairo.fill ctx; + + (* Draw an arrow on the robot *) + Cairo.move_to ctx (-. robot_size /. 4.) 0.; + Cairo.line_to ctx (robot_size /. 4.) 0.; + Cairo.line_to ctx 0. (-. robot_size /. 4.); + Cairo.line_to ctx 0. (robot_size /. 4.); + Cairo.line_to ctx (robot_size /. 4.) 0.; + set_color ctx Black; + Cairo.stroke ctx; + + let ctx = Cairo_lablgtk.create widget#misc#window in + Cairo.set_source_surface ctx surface 0. 0.; + Cairo.rectangle ctx 0. 0. width height; + Cairo.fill ctx; + Cairo.surface_finish surface +end + +(* +-----------------------------------------------------------------+ + | Entry point | + +-----------------------------------------------------------------+ *) + +lwt () = + lwt bus = Krobot_bus.get () in + ignore (GMain.init ()); + Lwt_glib.install (); + + let waiter, wakener = wait () in + + let ui = new Krobot_viewer_ui.window () in + ignore (ui#window#connect#destroy ~callback:(wakeup wakener)); + ui#window#show (); + + let lcd = LCD.create () in + ignore (ui#lcd#event#connect#expose (fun ev -> LCD.draw ui#lcd lcd; true)); + + let board = Board.({ state = { x = 0.2; y = 1.9; theta = 2. *. atan (-1.) } }) in + ignore (ui#scene#event#connect#expose (fun ev -> Board.draw ui#scene board; true)); + + waiter diff --git a/info/control2011/src/tools/krobot_viewer_ui.glade b/info/control2011/src/tools/krobot_viewer_ui.glade new file mode 100644 index 0000000..ade135a --- /dev/null +++ b/info/control2011/src/tools/krobot_viewer_ui.glade @@ -0,0 +1,207 @@ +<?xml version="1.0"?> +<glade-interface> + <!-- interface-requires gtk+ 2.16 --> + <!-- interface-naming-policy project-wide --> + <widget class="GtkWindow" id="window"> + <property name="default_width">1024</property> + <property name="default_height">768</property> + <child> + <widget class="GtkVBox" id="vbox1"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <child> + <widget class="GtkMenuBar" id="menubar1"> + <property name="visible">True</property> + <child> + <widget class="GtkMenuItem" id="menuitem1"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Fichier</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu1"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem1"> + <property name="label">gtk-new</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem2"> + <property name="label">gtk-open</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem3"> + <property name="label">gtk-save</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem4"> + <property name="label">gtk-save-as</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkSeparatorMenuItem" id="separatormenuitem1"> + <property name="visible">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem5"> + <property name="label">gtk-quit</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem2"> + <property name="visible">True</property> + <property name="label" translatable="yes">É_dition</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu2"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem6"> + <property name="label">gtk-cut</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem7"> + <property name="label">gtk-copy</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem8"> + <property name="label">gtk-paste</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem9"> + <property name="label">gtk-delete</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem3"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Affichage</property> + <property name="use_underline">True</property> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem4"> + <property name="visible">True</property> + <property name="label" translatable="yes">Aid_e</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu3"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem10"> + <property name="label">gtk-about</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <child> + <widget class="GtkDrawingArea" id="scene"> + <property name="visible">True</property> + <property name="app_paintable">True</property> + <property name="double_buffered">False</property> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkVBox" id="vbox2"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <child> + <widget class="GtkDrawingArea" id="lcd"> + <property name="width_request">404</property> + <property name="height_request">97</property> + <property name="visible">True</property> + <property name="app_paintable">True</property> + <property name="double_buffered">False</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkViewport" id="viewport1"> + <property name="visible">True</property> + <property name="resize_mode">queue</property> + <child> + <placeholder/> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + </widget> + </child> + </widget> +</glade-interface> hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-20 19:53:46
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via a414b505a146c51f221aaa54266e42584d4ebc33 (commit) via 1731b5b47d5adf3683718e89626696bad72cbdce (commit) via 838ebbba06f9f20d274c14c0441bed671b6d2656 (commit) from 83c186985a65096c7239b31b96be7dc1d5bef443 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a414b505a146c51f221aaa54266e42584d4ebc33 Author: Jérémie Dimino <je...@di...> Date: Sun Mar 20 20:53:16 2011 +0100 [info] remove Krobot_init commit 1731b5b47d5adf3683718e89626696bad72cbdce Author: Jérémie Dimino <je...@di...> Date: Sun Mar 20 12:30:20 2011 +0100 [info] install the D-Bus configuration file commit 838ebbba06f9f20d274c14c0441bed671b6d2656 Author: Jérémie Dimino <je...@di...> Date: Sun Mar 20 20:48:58 2011 +0100 [info] merge ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 93f2fed..3d6033b 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -13,6 +13,7 @@ BuildTools: ocamlbuild Plugins: DevFiles (0.2), META (0.2) Synopsis: [Kro]bot Description: Control program for the Eurobot robotic cup. +FilesAB: src/driver/bus.conf.ab # +-------------------------------------------------------------------+ # | Libraries | @@ -29,8 +30,7 @@ Library krobot Krobot_can, Krobot_bus, Krobot_message, - Krobot_service, - Krobot_init + Krobot_service Library "krobot-can" FindlibName: can @@ -64,6 +64,7 @@ Executable "krobot-driver" CompiledObject: best MainIs: krobot_driver.ml BuildDepends: krobot.can, lwt.syntax + DataFiles: bus.conf # +-------------------------------------------------------------------+ # | Tools | @@ -111,6 +112,7 @@ Executable "krobot-plot" MainIs: krobot_plot.ml BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads + # +-------------------------------------------------------------------+ # | Examples | # +-------------------------------------------------------------------+ diff --git a/info/control2011/krobot-api.odocl b/info/control2011/krobot-api.odocl index c80c72a..f4916e1 100644 --- a/info/control2011/krobot-api.odocl +++ b/info/control2011/krobot-api.odocl @@ -1,9 +1,8 @@ # OASIS_START -# DO NOT EDIT (digest: 979bfe64930f512bd800c4336aa992aa) +# DO NOT EDIT (digest: 0d5bc1930a2026d83d7053264b79ba8f) src/lib/Krobot_can src/lib/Krobot_bus src/lib/Krobot_message src/lib/Krobot_service -src/lib/Krobot_init src/can/Krobot_can_bus # OASIS_STOP diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 523013d..b2af3c8 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,9 +1,9 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: c9d539f09d0003ab7eefa01ee368b5d6) *) +(* DO NOT EDIT (digest: 80867cfdd6884c39f5a6799ecb9f747d) *) (* - Regenerated by OASIS v0.2.0 + Regenerated by OASIS v0.2.0~alpha1 Visit http://oasis.forge.ocamlcore.org for more information and documentation about functions used in this file. *) @@ -5039,7 +5039,7 @@ let setup_t = pre_command = [(OASISExpr.EBool true, None)]; post_command = [(OASISExpr.EBool true, None)]; }; - files_ab = []; + files_ab = ["src/driver/bus.conf.ab"]; sections = [ Library @@ -5105,8 +5105,7 @@ let setup_t = "Krobot_can"; "Krobot_bus"; "Krobot_message"; - "Krobot_service"; - "Krobot_init" + "Krobot_service" ]; lib_internal_modules = []; lib_findlib_parent = None; @@ -5233,7 +5232,7 @@ let setup_t = ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; - bs_data_files = []; + bs_data_files = [("bus.conf", None)]; bs_ccopt = [(OASISExpr.EBool true, [])]; bs_cclib = [(OASISExpr.EBool true, [])]; bs_dlllib = [(OASISExpr.EBool true, [])]; @@ -5413,7 +5412,7 @@ let setup_t = schema_data = PropList.Data.create (); plugin_data = []; }; - version = "0.2.0"; + version = "0.2.0~alpha1"; };; let setup () = BaseSetup.setup setup_t;; diff --git a/info/control2011/src/driver/bus.conf.ab b/info/control2011/src/driver/bus.conf.ab new file mode 100644 index 0000000..ae988d4 --- /dev/null +++ b/info/control2011/src/driver/bus.conf.ab @@ -0,0 +1 |
From: Jérémie D. <Ba...@us...> - 2011-03-19 22:00:51
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 83c186985a65096c7239b31b96be7dc1d5bef443 (commit) from 95ab414ec8f22c7cf492ed89c459b8a79c1904fd (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 83c186985a65096c7239b31b96be7dc1d5bef443 Author: Jérémie Dimino <je...@di...> Date: Sat Mar 19 22:59:29 2011 +0100 [info] fix krobot-replay ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/tools/krobot_replay.ml b/info/control2011/src/tools/krobot_replay.ml index ffabded..a299169 100644 --- a/info/control2011/src/tools/krobot_replay.ml +++ b/info/control2011/src/tools/krobot_replay.ml @@ -12,6 +12,12 @@ open Lwt open Lwt_react +let rec loop bus ic delta prev_timestamp = + lwt timestamp, frame = Lwt_io.read_value ic in + lwt () = Lwt_unix.sleep (timestamp -. prev_timestamp) in + lwt () = Krobot_can.send bus (timestamp +. delta, frame) in + loop bus ic delta timestamp + lwt () = let file = ref "krobot.record" in Krobot_init.arg "-input" (Arg.Set_string file) "<file> input file"; @@ -25,9 +31,6 @@ lwt () = (* Compute the difference of time to add to each timestamp. *) let delta = Unix.gettimeofday () -. timestamp in lwt () = Krobot_can.send bus (timestamp +. delta, frame) in - while_lwt true do - lwt timestamp, frame = Lwt_io.read_value ic in - Krobot_can.send bus (timestamp +. delta, frame) - done + loop bus ic delta timestamp with End_of_file -> Lwt_io.close ic hooks/post-receive -- krobot |
From: Nicolas D. <Ba...@us...> - 2011-03-19 20:08:17
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 95ab414ec8f22c7cf492ed89c459b8a79c1904fd (commit) from 93954a49f74cb2037113e6746db7812d3e0b85e5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 95ab414ec8f22c7cf492ed89c459b8a79c1904fd Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Mar 19 21:07:27 2011 +0100 [USB_CAN/Firmware] Do some more logic wrapping ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/usb_can/main.c b/elec/boards/USB_CAN/Firmware/usb_can/main.c index c86fca5..2da2acd 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/main.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/main.c @@ -47,14 +47,14 @@ PROC_DEFINE_STACK(stack_can_recv, KERN_MINSTACKSIZE * 4); PROC_DEFINE_STACK(stack_blinky, KERN_MINSTACKSIZE * 2); static struct Serial ser; +static usb_can usbcan; static void init(void) { - can_config cfg; cfg.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP; - /* CAN driver in loopback mode */ + /* 1 Mbit by default (FIXME: O'RLY?) */ cfg.btr = CAN_BTR_SJW(0) | CAN_BTR_TS1(8) | CAN_BTR_TS2(1) | CAN_BTR_BRP(6); cfg.n_filters = 0; @@ -83,6 +83,9 @@ static void init(void) /* Initialize Serial driver */ ser_init(&ser, SER_UART3); + /* Initialize USB-CAN logic */ + usb_can_init(&usbcan, CAND1, &ser); + /* * Kernel initialization: processes (allow to create and dispatch * processes using proc_new()). @@ -97,9 +100,9 @@ static void NORETURN serial_receive_process(void) for (;;) { i = !i; - nbytes = kfile_gets(&ser.fd, command, MAX_CMD_SIZE+1); + nbytes = kfile_gets(&usbcan.ser->fd, command, MAX_CMD_SIZE+1); if (nbytes != EOF) { - retval = usb_can_execute_command(CAND1, &ser, command); + retval = usb_can_execute_command(&usbcan, command); if (i) LED1_ON(); else @@ -118,9 +121,9 @@ static void NORETURN can_receive_process(void) { for (;;) { - received = can_receive(CAND1, &frame, ms_to_ticks(100)); + received = can_receive(usbcan.can, &frame, ms_to_ticks(100)); if (received) { - retval = usb_can_emit(CAND1, &ser, &frame); + retval = usb_can_emit(&usbcan, &frame); kprintf("received something... %d %08lx %08lx\n", frame.ide ? frame.eid:frame.sid, frame.data32[0], frame.data32[1]); } } diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c index 03e505e..ef58b89 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c @@ -45,8 +45,41 @@ INLINE uint32_t nibble_to_uint32(char *nibbles, size_t length) { return ret; } +void usb_can_init(usb_can *usbcan, can_driver *can, struct Serial *ser) { -int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *command) { + usbcan->can = can; + usbcan->ser = ser; + usbcan->is_open = false; + usbcan->timestamped = false; + +} + +void usb_can_open(usb_can *usbcan) { + if (usbcan->is_open) + kfile_write(&usbcan->ser->fd, "\a", 1); + else { + usbcan->is_open = true; + kfile_write(&usbcan->ser->fd, "\r", 1); + } +} + +void usb_can_close(usb_can *usbcan) { + if (usbcan->is_open) { + usbcan->is_open = false; + kfile_write(&usbcan->ser->fd, "\r", 1); + } + else { + kfile_write(&usbcan->ser->fd, "\a", 1); + } +} + +void usb_can_set_baudrate(usb_can *usbcan, char *baudrate) { + /* FIXME: Implement it for real! */ + (void)baudrate; + kfile_write(&usbcan->ser->fd, "\r", 1); +} + +int usb_can_execute_command(usb_can *usbcan, char *command) { can_tx_frame frame; bool send, ret; @@ -63,23 +96,29 @@ int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *com switch (command[0]) { case 'V': /* Version number */ - kfile_write(&serial->fd, "V0402\r", 6); + kfile_write(&usbcan->ser->fd, "V0402\r", 6); break; case 'N': /* Serial number */ - kfile_write(&serial->fd, "NKROB\r", 6); + kfile_write(&usbcan->ser->fd, "NKROB\r", 6); break; case 'O': /* Open CAN Channel */ - /* FIXME: Implement! */ + usb_can_open(usbcan); break; case 'S': /* Set CAN Channel Baudrate numerically */ - /* FIXME: Implement! */ - break; case 's': /* Set CAN Channel Baudrate with BTR0/1 */ - /* FIXME: Implement! */ + usb_can_set_baudrate(usbcan, command); + break; + case 'Z': + /* Set Timestamped packet mode */ + if (command[1] == '0') + usbcan->timestamped = false; + else if (command[0] == '1') + usbcan->timestamped = true; + kfile_write(&usbcan->ser->fd, "\r", 1); break; case 'R': /* Send an extended RTR frame */ @@ -120,26 +159,22 @@ int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *com } if (send) { - ret = can_transmit(candrv, &frame, ms_to_ticks(10)); + ret = can_transmit(usbcan->can, &frame, ms_to_ticks(10)); if (ret) - kfile_write(&serial->fd, frame.ide ? "Z\r" : "z\r", 2); + kfile_write(&usbcan->ser->fd, frame.ide ? "Z\r" : "z\r", 2); else - kfile_write(&serial->fd, "\a", 1); + kfile_write(&usbcan->ser->fd, "\a", 1); } return 0; } -int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx_frame *frame) { +int usb_can_emit(usb_can *usbcan, can_rx_frame *frame) { char buffer[32] = ""; int i = 0, j = 0; uint16_t timestamp; - /* The timestamp should wrap around every minute (it works until - the 32 bits of timer_clock are exhausted) */ - timestamp = ticks_to_ms(timer_clock()) % 60000; - buffer[0] = frame->rtr ? 'r' : 't'; // Extended identifier : uppercase identifier @@ -159,13 +194,19 @@ int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx for(j = 0; j < frame->dlc; i+=2, j++) sprintf(&buffer[i], "%02x", frame->data8[j]); - sprintf(&buffer[i], "%04x", timestamp); - i+=4; + if (usbcan->timestamped) { + /* The timestamp should wrap around every minute (it works until + the 32 bits of timer_clock are exhausted) */ + timestamp = ticks_to_ms(timer_clock()) % 60000; + + sprintf(&buffer[i], "%04x", timestamp); + i+=4; + } buffer[i] = '\r'; i++; - kfile_write(&serial->fd, buffer, i); + kfile_write(&usbcan->ser->fd, buffer, i); return 0; } diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h index efc7d0c..960f819 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h @@ -1,7 +1,24 @@ -/* - * USB CAN specific logic +/** + * USB-CAN converter + * + * This file contains the logic for the USB <-> CAN transceiver. + * * Copyright © 2011 Nicolas Dandrimont <ol...@cr...> - * License : GPLv3+ + * Authors: Nicolas Dandrimont <ol...@cr...> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ #ifndef USB_CAN_H @@ -14,8 +31,22 @@ #include <drv/timer.h> #include <io/kfile.h> -int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *command); +typedef struct _usb_can { + can_driver *can; // CAN Device + struct Serial *ser; // Serial Device + bool is_open; // Channel open? + bool timestamped; // Emit timestamps? +} usb_can; -int usb_can_emit(can_driver *candrv, struct Serial *serial, can_rx_frame *frame); +void usb_can_init(usb_can *usbcan, can_driver *can, struct Serial *ser); + +void usb_can_open(usb_can *usbcan); +void usb_can_close(usb_can *usbcan); + +void usb_can_set_baudrate(usb_can *usbcan, char *baudrate); + +int usb_can_execute_command(usb_can *usbcan, char *command); + +int usb_can_emit(usb_can *usbcan, can_rx_frame *frame); #endif /* !USB_CAN_H */ hooks/post-receive -- krobot |
From: Nicolas D. <Ba...@us...> - 2011-03-19 17:58:34
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 93954a49f74cb2037113e6746db7812d3e0b85e5 (commit) via a15cb73960f845d1290f66fafa70b17e5377dd47 (commit) via 4bfac45208500bd33f1e2deb6e3a0de3b983cf74 (commit) via e9f522ea891327263f6c9f19130a78d357d59848 (commit) from 2c65274daf59dc657959b6cc7b3bc400e3779c7c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 93954a49f74cb2037113e6746db7812d3e0b85e5 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Mar 19 18:56:07 2011 +0100 [USB_CAN/Firmware] Rewrite copyright notices commit a15cb73960f845d1290f66fafa70b17e5377dd47 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Mar 19 18:54:38 2011 +0100 [USB_CAN/Firmware] Implement the CAN sending logic commit 4bfac45208500bd33f1e2deb6e3a0de3b983cf74 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Mar 19 18:53:14 2011 +0100 [USB_CAN/Firmware] Move timestamp computation to the usb_can_emit function commit e9f522ea891327263f6c9f19130a78d357d59848 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Mar 19 17:40:43 2011 +0100 [USB_CAN/Firmware] Remove ugly printf's ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/bertos/drv/can.c b/elec/boards/USB_CAN/Firmware/bertos/drv/can.c index d245c2d..a4137dd 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/drv/can.c +++ b/elec/boards/USB_CAN/Firmware/bertos/drv/can.c @@ -33,6 +33,7 @@ * \brief CAN driver (implementation) * * \author Nicolas Dandrimont <Nic...@cr...> + * */ #include <drv/can.h> @@ -115,22 +116,16 @@ bool can_transmit(can_driver *drv, can_tx_frame *frame, ticks_t timeout) { bool ret; proc_forbid(); - kprintf("Lock xmit (timeout=%d)\n", timeout); while ((drv->state == CAN_SLEEP) || !can_hw_can_transmit(drv)) { - kprintf("Can't xmit\n"); ret = event_waitTimeout(&drv->tx_empty_event, timeout); - kprintf("After wait (%d)\n", ret); if (ret != true) { proc_permit(); return false; } } - - kprintf("Before xmit\n"); + can_hw_transmit(drv, frame); - kprintf("After xmit\n"); proc_permit(); - kprintf("Unlock xmit\n"); return true; } diff --git a/elec/boards/USB_CAN/Firmware/bertos/drv/can.h b/elec/boards/USB_CAN/Firmware/bertos/drv/can.h index 07a7d81..9d47528 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/drv/can.h +++ b/elec/boards/USB_CAN/Firmware/bertos/drv/can.h @@ -42,6 +42,8 @@ * $WIZ$ module_name = "can" * $WIZ$ module_configuration = "bertos/cfg/cfg_can.h" * $WIZ$ module_supports = "stm32" + * $WIZ$ module_depends = "timer", "signal" + * */ diff --git a/elec/boards/USB_CAN/Firmware/usb_can/main.c b/elec/boards/USB_CAN/Firmware/usb_can/main.c index 01442bf..c86fca5 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/main.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/main.c @@ -1,11 +1,15 @@ /** - * \file - * <!-- - * This file is part of BeRTOS. + * USB-CAN converter * - * Bertos is free software; you can redistribute it and/or modify + * This file is the entry point for an USB <-> CAN transceiver. + * + * Copyright © 2011 Nicolas Dandrimont <ol...@cr...> + * Authors: Nicolas Dandrimont <ol...@cr...> + * Xavier Lagorce <Xav...@cr...> + * + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -14,29 +18,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2010 Develer S.r.l. (http://www.develer.com/) - * - * --> - * - * \author Andrea Righi <ar...@de...> + * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * \brief Kernel project. - * - * This is a minimalist kernel project: it just initializes the hardware and - * creates an independent process to blink an LED, while the main loop - * continues to monitor the stack utilization of all the processes. */ #include "hw/hw_led.h" @@ -112,23 +95,11 @@ static void NORETURN serial_receive_process(void) int nbytes, retval, i = 0; char command[MAX_CMD_SIZE+1]; - can_tx_frame frame; - - frame.ide = 1; - frame.eid = 0x42; - frame.dlc = 4; - frame.data8[0] = 1; - frame.data8[1] = 1; - frame.data8[2] = 1; - frame.data8[3] = 1; - for (;;) { i = !i; nbytes = kfile_gets(&ser.fd, command, MAX_CMD_SIZE+1); if (nbytes != EOF) { retval = usb_can_execute_command(CAND1, &ser, command); - can_transmit(CAND1, &frame, ms_to_ticks(42)); - kprintf("got %d bytes: [%s]\n", nbytes, command); if (i) LED1_ON(); else @@ -143,13 +114,15 @@ static void NORETURN can_receive_process(void) { can_rx_frame frame; int retval; - int32_t timestamp; + bool received = false; + for (;;) { - can_receive(CAND1, &frame, ms_to_ticks(100)); - timestamp = ticks_to_ms(timer_clock()) % 60000; - retval = usb_can_emit(CAND1, &ser, &frame, (uint16_t)timestamp); - kprintf("received something... %d %08lx %08lx\n", frame.ide ? frame.eid:frame.sid, frame.data32[0], frame.data32[1]); + received = can_receive(CAND1, &frame, ms_to_ticks(100)); + if (received) { + retval = usb_can_emit(CAND1, &ser, &frame); + kprintf("received something... %d %08lx %08lx\n", frame.ide ? frame.eid:frame.sid, frame.data32[0], frame.data32[1]); + } } } diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c index bb16436..03e505e 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c @@ -1,14 +1,144 @@ +/** + * USB-CAN converter + * + * This file contains the logic for the USB <-> CAN transceiver. + * + * Copyright © 2011 Nicolas Dandrimont <ol...@cr...> + * Authors: Nicolas Dandrimont <ol...@cr...> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + #include "usb_can.h" -int usb_can_execute_command(UNUSED_ARG(can_driver *, candrv), UNUSED_ARG(struct Serial *, serial), UNUSED_ARG(char *, command)) { +INLINE uint32_t nibble_to_uint32(char *nibbles, size_t length) { + + char *p; + uint32_t ret = 0; + uint8_t tmp = 0; + + for (p = nibbles; p < nibbles + length; p++) { + ret = (ret << 4); + if ('0' <= *p && *p <= '9') + tmp = *p - '0'; + else if ('A' <= *p && *p <= 'F') + tmp = (*p - 'A') + 10; + else if ('a' <= *p && *p <= 'f') + tmp = (*p - 'a') + 10; + else + tmp = 0; + ret = ret + tmp; + } + + return ret; +} + + +int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *command) { + + can_tx_frame frame; + bool send, ret; + int i; + + frame.rtr = 0; + frame.ide = 0; + frame.eid = 0; + frame.sid = 0; + frame.dlc = 0; + frame.data32[0] = 0; + frame.data32[1] = 0; + + switch (command[0]) { + case 'V': + /* Version number */ + kfile_write(&serial->fd, "V0402\r", 6); + break; + case 'N': + /* Serial number */ + kfile_write(&serial->fd, "NKROB\r", 6); + break; + case 'O': + /* Open CAN Channel */ + /* FIXME: Implement! */ + break; + case 'S': + /* Set CAN Channel Baudrate numerically */ + /* FIXME: Implement! */ + break; + case 's': + /* Set CAN Channel Baudrate with BTR0/1 */ + /* FIXME: Implement! */ + break; + case 'R': + /* Send an extended RTR frame */ + frame.rtr = 1; + frame.ide = 1; + frame.eid = nibble_to_uint32(&command[1], 8); + frame.dlc = nibble_to_uint32(&command[9], 1); + for (i = 0; i < frame.dlc; i++) + frame.data8[i] = nibble_to_uint32(&command[10 + 2*i], 2); + send = true; + break; + case 'r': + /* Send a classic RTR frame */ + frame.rtr = 1; + frame.sid = nibble_to_uint32(&command[1], 3); + frame.dlc = nibble_to_uint32(&command[4], 1); + for (i = 0; i < frame.dlc; i++) + frame.data8[i] = nibble_to_uint32(&command[5 + 2*i], 2); + send = true; + break; + case 'T': + frame.ide = 1; + frame.eid = nibble_to_uint32(&command[1], 8); + frame.dlc = nibble_to_uint32(&command[9], 1); + for (i = 0; i < frame.dlc; i++) + frame.data8[i] = nibble_to_uint32(&command[10 + 2*i], 2); + send = true; + break; + case 't': + frame.sid = nibble_to_uint32(&command[1], 3); + frame.dlc = nibble_to_uint32(&command[4], 1); + for (i = 0; i < frame.dlc; i++) + frame.data8[i] = nibble_to_uint32(&command[5 + 2*i], 2); + send = true; + break; + default: + break; + } + + if (send) { + ret = can_transmit(candrv, &frame, ms_to_ticks(10)); + if (ret) + kfile_write(&serial->fd, frame.ide ? "Z\r" : "z\r", 2); + else + kfile_write(&serial->fd, "\a", 1); + } return 0; } -int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx_frame *frame, uint16_t timestamp) { +int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx_frame *frame) { char buffer[32] = ""; int i = 0, j = 0; + uint16_t timestamp; + + /* The timestamp should wrap around every minute (it works until + the 32 bits of timer_clock are exhausted) */ + timestamp = ticks_to_ms(timer_clock()) % 60000; buffer[0] = frame->rtr ? 'r' : 't'; diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h index 5a8c1ee..efc7d0c 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h @@ -16,6 +16,6 @@ int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *command); -int usb_can_emit(can_driver *candrv, struct Serial *serial, can_rx_frame *frame, uint16_t timestamp); +int usb_can_emit(can_driver *candrv, struct Serial *serial, can_rx_frame *frame); #endif /* !USB_CAN_H */ hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-19 17:11:57
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 2c65274daf59dc657959b6cc7b3bc400e3779c7c (commit) from cb716f5381d356396981452c97ed398603a58265 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2c65274daf59dc657959b6cc7b3bc400e3779c7c Author: Jérémie Dimino <je...@di...> Date: Sat Mar 19 17:52:29 2011 +0100 [info] add two tools to forward the D-Bus connection ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index b85b498..93f2fed 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -90,6 +90,20 @@ Executable "krobot-replay" MainIs: krobot_replay.ml BuildDepends: krobot, lwt.syntax +Executable "krobot-remote" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_remote.ml + BuildDepends: krobot, lwt.syntax + +Executable "krobot-local" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_local.ml + BuildDepends: krobot, lwt.syntax + Executable "krobot-plot" Path: src/tools Install: true diff --git a/info/control2011/_tags b/info/control2011/_tags index 9c6da6c..c48d120 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 404e613a369861087dfd1cb3215a1db4) +# DO NOT EDIT (digest: 3f2673f16efc8fd23f421702ae380100) # Library krobot-interfaces "src/interfaces": include <src/interfaces/*.ml{,i}>: pkg_obus @@ -44,6 +44,12 @@ <src/driver/*.ml{,i}>: pkg_obus <src/driver/*.ml{,i}>: pkg_lwt.unix <src/driver/*.ml{,i}>: pkg_lwt.syntax +# Executable krobot-remote +<src/tools/krobot_remote.{native,byte}>: use_krobot +<src/tools/krobot_remote.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_remote.{native,byte}>: pkg_obus +<src/tools/krobot_remote.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_remote.{native,byte}>: pkg_lwt.syntax # Executable krobot-replay <src/tools/krobot_replay.{native,byte}>: use_krobot <src/tools/krobot_replay.{native,byte}>: use_krobot-interfaces @@ -63,6 +69,12 @@ <examples/*.ml{,i}>: pkg_obus <examples/*.ml{,i}>: pkg_lwt.unix <examples/*.ml{,i}>: pkg_lwt.syntax +# Executable krobot-local +<src/tools/krobot_local.{native,byte}>: use_krobot +<src/tools/krobot_local.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_local.{native,byte}>: pkg_obus +<src/tools/krobot_local.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_local.{native,byte}>: pkg_lwt.syntax # Executable krobot-record <src/tools/krobot_record.{native,byte}>: use_krobot <src/tools/krobot_record.{native,byte}>: use_krobot-interfaces diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 3e81a39..523013d 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: c0061e3e8da638912d5008f7a294c616) *) +(* DO NOT EDIT (digest: c9d539f09d0003ab7eefa01ee368b5d6) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5244,6 +5244,33 @@ let setup_t = {exec_custom = false; exec_main_is = "krobot_driver.ml"; }); Executable ({ + cs_name = "krobot-remote"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + {exec_custom = false; exec_main_is = "krobot_remote.ml"; }); + Executable + ({ cs_name = "krobot-replay"; cs_data = PropList.Data.create (); cs_plugin_data = []; @@ -5298,6 +5325,33 @@ let setup_t = {exec_custom = false; exec_main_is = "dump_can.ml"; }); Executable ({ + cs_name = "krobot-local"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + {exec_custom = false; exec_main_is = "krobot_local.ml"; }); + Executable + ({ cs_name = "krobot-record"; cs_data = PropList.Data.create (); cs_plugin_data = []; diff --git a/info/control2011/src/tools/krobot_local.ml b/info/control2011/src/tools/krobot_local.ml new file mode 100644 index 0000000..0983e32 --- /dev/null +++ b/info/control2011/src/tools/krobot_local.ml @@ -0,0 +1,30 @@ +(* + * krobot_local.ml + * --------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +open Lwt + +let rec copy ta tb = + lwt msg = OBus_transport.recv ta in + lwt () = OBus_transport.send tb msg in + copy ta tb + +lwt () = + lwt (_, ta) = OBus_transport.of_addresses [OBus_address.make "unix" [("abstract", "krobot")]] in + lwt () = Lwt_io.write_char Lwt_io.stdout ' ' in + let tb = + OBus_transport.make + ~send:(fun msg -> OBus_wire.write_message Lwt_io.stdout msg) + ~recv:(fun () -> OBus_wire.read_message Lwt_io.stdin) + ~shutdown:return + () + in + try_lwt + copy ta tb <&> copy tb ta + with End_of_file -> + return () diff --git a/info/control2011/src/tools/krobot_remote.ml b/info/control2011/src/tools/krobot_remote.ml new file mode 100644 index 0000000..c66de43 --- /dev/null +++ b/info/control2011/src/tools/krobot_remote.ml @@ -0,0 +1,48 @@ +(* + * krobot_remote.ml + * ---------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +open Lwt + +let rec copy ta tb = + lwt msg = OBus_transport.recv ta in + lwt () = OBus_transport.send tb msg in + copy ta tb + +let handle_connection server ta = + ignore ( + let process = Lwt_process.open_process ("ssh", [|"ssh"; "krobot"; "krobot-local"|]) in + try_lwt + lwt _ = Lwt_io.read_char process#stdout in + let tb = + OBus_transport.make + ~send:(fun msg -> OBus_wire.write_message process#stdin msg) + ~recv:(fun () -> OBus_wire.read_message process#stdout) + ~shutdown:(fun () -> process#close >> return ()) + () + in + ignore ( + try_lwt + copy ta tb <&> copy tb ta + with exn -> + OBus_transport.shutdown ta <&> OBus_transport.shutdown tb + ); + return () + with exn -> + lwt _ = process#close and () = OBus_transport.shutdown ta in + lwt () = Lwt_log.error_f ~exn "failed to open connection" in + return () + ) + +lwt () = + lwt server = + OBus_server.make_lowlevel + ~addresses:[OBus_address.make "unix" [("abstract", "krobot")]] + handle_connection + in + fst (wait ()) hooks/post-receive -- krobot |
From: Nicolas D. <Ba...@us...> - 2011-03-19 16:32:54
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via cb716f5381d356396981452c97ed398603a58265 (commit) from 6409bfb8555556ae6d525498687b33f1ec8d125f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit cb716f5381d356396981452c97ed398603a58265 Author: Nicolas Dandrimont <Nic...@cr...> Date: Fri Mar 18 23:52:18 2011 +0100 [USB_CAN/Firmware] Upgrade BeRTOS ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_can.h b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_can.h index 827bc96..9d92690 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_can.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_can.h @@ -33,6 +33,7 @@ * \brief Configuration file for the CAN module. * * \author Nicolas Dandrimont <Nic...@cr...> + * */ #ifndef CFG_CAN_H @@ -54,4 +55,13 @@ */ #define CAN_LOG_FORMAT LOG_FMT_VERBOSE +/** + * CAN remapping + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "can_stm32_remaps" + * $WIZ$ supports = "stm32" + */ +#define CAN_STM32_REMAP CAN_STM32_PORTA + #endif /* CFG_CAN_H */ diff --git a/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_led_7seg.h b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_led_7seg.h new file mode 100644 index 0000000..d854b11 --- /dev/null +++ b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_led_7seg.h @@ -0,0 +1,80 @@ +/** + * \file cfg_led_7seg.h + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2010 Develer S.r.l. (http://www.develer.com/) + * --> + * + * \brief Configuration file for led 7 segment display. + * + * \author Fabio Bizzi <fb...@bi...> + * + * \addtogroup SevenSegDisplay 7 Segments LED Displays Driver + * \{ + * + */ + +#ifndef CFG_LED_7SEG_H +#define CFG_LED_7SEG_H + +/** + * Use a Common Cathode display. + * $WIZ$ type = "boolean" + */ +#define CONFIG_LED_7SEG_CCAT 0 + +/** + * Number of digit present in the LED display. + * $WIZ$ type = "int" + * $WIZ$ min = 1 + * $WIZ$ max = 8 + */ +#define CONFIG_LED_7SEG_DIGIT 4 + +/** + * Max lenght of the string to be displayed. + * $WIZ$ type = "int" + * $WIZ$ min = 16 + * $WIZ$ max = 255 + */ +#define CONFIG_LED_7SEG_STRLEN 255 + +/** + * Default scrolling speed (ms * CONFIG_LED_7SEG_RTIME). + * $WIZ$ type = "int" + */ +#define CONFIG_LED_7SEG_SSPEED 10 + +/** + * Default refresh time (ms). + * $WIZ$ type = "int" + */ +#define CONFIG_LED_7SEG_RTIME 5 + +#endif /* CFG_LED_7SEG_H */ + /** \} */ //defgroup drivers + diff --git a/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_pwm.h b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_pwm.h index 595189e..68d6283 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_pwm.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cfg/cfg_pwm.h @@ -53,4 +53,12 @@ */ #define PWM_LOG_FORMAT LOG_FMT_VERBOSE +/** + * Enable the OLD pwm API. + * Not recommended for new projects. + * + * $WIZ$ type = "boolean" + */ +#define CFG_PWM_ENABLE_OLD_API 1 + #endif /* CFG_PWM_H */ diff --git a/elec/boards/USB_CAN/Firmware/bertos/cfg/compiler.h b/elec/boards/USB_CAN/Firmware/bertos/cfg/compiler.h index ac60848..3a2f34c 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cfg/compiler.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cfg/compiler.h @@ -450,6 +450,9 @@ #endif #endif +/** User defined callback type */ +typedef void (*Hook)(void *); + /** Bulk storage large enough for both pointers or integers. */ typedef void * iptr_t; diff --git a/elec/boards/USB_CAN/Firmware/bertos/cfg/debug.h b/elec/boards/USB_CAN/Firmware/bertos/cfg/debug.h index efa26e1..ef6717c 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cfg/debug.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cfg/debug.h @@ -55,16 +55,21 @@ #include <cfg/os.h> #include <cfg/compiler.h> +#include "cfg/cfg_debug.h" /* CONFIG_KDEBUG_* */ /* * Defaults for rarely used config stuff. */ -#ifndef CONFIG_KDEBUG_DISABLE_TRACE -#define CONFIG_KDEBUG_DISABLE_TRACE 0 +#ifndef CONFIG_KDEBUG_TRACE +#define CONFIG_KDEBUG_TRACE 1 #endif -#ifndef CONFIG_KDEBUG_ASSERT_NO_TEXT -#define CONFIG_KDEBUG_ASSERT_NO_TEXT 0 +#ifndef CONFIG_KDEBUG_VERBOSE_ASSERT +#define CONFIG_KDEBUG_VERBOSE_ASSERT 1 +#endif + +#ifndef CONFIG_KDEBUG_WALLS +#define CONFIG_KDEBUG_WALLS 1 #endif #if defined(__doxygen__) @@ -127,7 +132,6 @@ */ #define DB(x) x - #include "cfg/cfg_debug.h" /* CONFIG_KDEBUG_ASSERT_NO_TEXT */ #include <cpu/attr.h> /* CPU_HARVARD */ /* These are implemented in drv/kdebug.c */ @@ -163,7 +167,7 @@ int __check_wall(long *wall, int size, const char *name, const char *file, int line); #endif /* !CPU_HARVARD */ - #if !CONFIG_KDEBUG_ASSERT_NO_TEXT + #if CONFIG_KDEBUG_VERBOSE_ASSERT /** * Assert a pre-condition on code. */ @@ -203,7 +207,7 @@ || ((void *)(p) >= (void *)CPU_RAM_START)) \ ? 0 : __invalid_ptr((p), #p, THIS_FILE, __LINE__))) - #if !CONFIG_KDEBUG_DISABLE_TRACE + #if CONFIG_KDEBUG_TRACE #define TRACE __trace(__func__) #define TRACEMSG(msg,...) __tracemsg(__func__, msg, ## __VA_ARGS__) #else @@ -211,19 +215,6 @@ #define TRACEMSG(...) do {} while(0) #endif - - /** - * \name Walls to detect data corruption - * \{ - */ - #define WALL_SIZE 8 - #define WALL_VALUE (long)0xABADCAFEL - #define DECLARE_WALL(name,size) long name[(size) / sizeof(long)]; - #define FWD_DECLARE_WALL(name,size) extern long name[(size) / sizeof(long)]; - #define INIT_WALL(name) __init_wall((name), countof(name)) - #define CHECK_WALL(name) __check_wall((name), countof(name), #name, THIS_FILE, __LINE__) - /*\}*/ - /** * Check that the given pointer actually points to an object * of the specified type. @@ -308,11 +299,6 @@ } #endif - #define DECLARE_WALL(name, size) /* nothing */ - #define FWD_DECLARE_WALL(name, size) /* nothing */ - #define INIT_WALL(name) do {} while (0) - #define CHECK_WALL(name) do {} while (0) - #define NEW_INSTANCE(CLASS) do {} while (0) #define DELETE_INSTANCE(CLASS) do {} while (0) #define ASSERT_ZERO_INSTANCES(CLASS) do {} while (0) @@ -336,6 +322,25 @@ #endif /* _DEBUG */ +#if CONFIG_KDEBUG_WALLS + /** + * \name Walls to detect data corruption + * \{ + */ + #define WALL_SIZE 8 + #define WALL_VALUE (long)0xABADCAFEL + #define DECLARE_WALL(name,size) long name[(size) / sizeof(long)]; + #define FWD_DECLARE_WALL(name,size) extern long name[(size) / sizeof(long)]; + #define INIT_WALL(name) __init_wall((name), countof(name)) + #define CHECK_WALL(name) __check_wall((name), countof(name), #name, THIS_FILE, __LINE__) + /*\}*/ +#else + #define DECLARE_WALL(name, size) /* nothing */ + #define FWD_DECLARE_WALL(name, size) /* nothing */ + #define INIT_WALL(name) do {} while (0) + #define CHECK_WALL(name) do {} while (0) +#endif + /** \} */ // defgroup debug #endif /* BERTOS_DEBUG_H */ diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.c index 397240e..c5780c3 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.c @@ -26,7 +26,7 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2008 Develer S.r.l. (http://www.develer.com/) + * Copyright 2011 Develer S.r.l. (http://www.develer.com/) * * --> * @@ -34,10 +34,11 @@ * \brief PWM hardware-specific implementation * * \author Daniele Basile <as...@de...> + * \author Francesco Sacchi <ba...@de...> */ +#include <drv/pwm.h> #include "pwm_at91.h" -#include "hw/pwm_map.h" #include <hw/hw_cpufreq.h> #include "cfg/cfg_pwm.h" @@ -50,201 +51,337 @@ #include <cfg/debug.h> #include <io/arm.h> +#include <cpu/irq.h> +#define PWM_HW_MAX_PRESCALER_STEP 10 +#define PWM_HW_MAX_PERIOD 0xFFFF -/** - * Register structure for pwm driver. - * This array content all data and register pointer - * to manage pwm peripheral device. - */ -static PwmChannel pwm_map[PWM_CNT] = -{ - {//PWM Channel 0 - .duty_zero = false, - .pol = false, - .pwm_pin = BV(PWM0), - .mode_reg = &PWM_CMR0, - .duty_reg = &PWM_CDTY0, - .period_reg = &PWM_CPRD0, - .update_reg = &PWM_CUPD0, - }, - {//PWM Channel 1 - .duty_zero = false, - .pol = false, - .pwm_pin = BV(PWM1), - .mode_reg = &PWM_CMR1, - .duty_reg = &PWM_CDTY1, - .period_reg = &PWM_CPRD1, - .update_reg = &PWM_CUPD1, - }, - {//PWM Channel 2 - .duty_zero = false, - .pol = false, - .pwm_pin = BV(PWM2), - .mode_reg = &PWM_CMR2, - .duty_reg = &PWM_CDTY2, - .period_reg = &PWM_CPRD2, - .update_reg = &PWM_CUPD2, - }, - {//PWM Channel 3 - .duty_zero = false, - .pol = false, - .pwm_pin = BV(PWM3), - .mode_reg = &PWM_CMR3, - .duty_reg = &PWM_CDTY3, - .period_reg = &PWM_CPRD3, - .update_reg = &PWM_CUPD3, - } -}; +#if CFG_PWM_ENABLE_OLD_API + #include "hw/pwm_map.h" + /** + * Register structure for pwm driver. + * This array content all data and register pointer + * to manage pwm peripheral device. + */ + static PwmChannel pwm_map[PWM_CNT] = + { + {//PWM Channel 0 + .duty_zero = false, + .pol = false, + .pwm_pin = BV(PWM0), + .mode_reg = &PWM_CMR0, + .duty_reg = &PWM_CDTY0, + .period_reg = &PWM_CPRD0, + .update_reg = &PWM_CUPD0, + }, + {//PWM Channel 1 + .duty_zero = false, + .pol = false, + .pwm_pin = BV(PWM1), + .mode_reg = &PWM_CMR1, + .duty_reg = &PWM_CDTY1, + .period_reg = &PWM_CPRD1, + .update_reg = &PWM_CUPD1, + }, + {//PWM Channel 2 + .duty_zero = false, + .pol = false, + .pwm_pin = BV(PWM2), + .mode_reg = &PWM_CMR2, + .duty_reg = &PWM_CDTY2, + .period_reg = &PWM_CPRD2, + .update_reg = &PWM_CUPD2, + }, + {//PWM Channel 3 + .duty_zero = false, + .pol = false, + .pwm_pin = BV(PWM3), + .mode_reg = &PWM_CMR3, + .duty_reg = &PWM_CDTY3, + .period_reg = &PWM_CPRD3, + .update_reg = &PWM_CUPD3, + } + }; -/** - * Get preiod from select channel - * - * \a dev channel - */ -pwm_period_t pwm_hw_getPeriod(PwmDev dev) -{ - return *pwm_map[dev].period_reg; -} -/** - * Set pwm waveform frequecy. - * - * \a freq in Hz - */ -void pwm_hw_setFrequency(PwmDev dev, uint32_t freq) -{ - uint32_t period = 0; + /** + * Get preiod from select channel + * + * \a dev channel + */ + pwm_period_t pwm_hw_getPeriod(PwmDev dev) + { + return *pwm_map[dev].period_reg; + } - for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++) + /** + * Set pwm waveform frequecy. + * + * \a freq in Hz + */ + void pwm_hw_setFrequency(PwmDev dev, uint32_t freq) { - period = CPU_FREQ / (BV(i) * freq); - LOG_INFO("period[%ld], prescale[%d]\n", period, i); - if ((period < PWM_HW_MAX_PERIOD) && (period != 0)) + uint32_t period = 0; + + for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++) { - //Clean previous channel prescaler, and set new - *pwm_map[dev].mode_reg &= ~PWM_CPRE_MCK_MASK; - *pwm_map[dev].mode_reg |= i; - //Set pwm period - *pwm_map[dev].period_reg = period; - break; + period = CPU_FREQ / (BV(i) * freq); + LOG_INFO("period[%ld], prescale[%d]\n", period, i); + if ((period < PWM_HW_MAX_PERIOD) && (period != 0)) + { + //Clean previous channel prescaler, and set new + *pwm_map[dev].mode_reg &= ~PWM_CPRE_MCK_MASK; + *pwm_map[dev].mode_reg |= i; + //Set pwm period + *pwm_map[dev].period_reg = period; + break; + } } + + LOG_INFO("PWM ch[%d] period[%ld]\n", dev, period); } - LOG_INFO("PWM ch[%d] period[%ld]\n", dev, period); -} + /** + * Set pwm duty cycle. + * + * \a duty value 0 - 2^16 + */ + void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty) + { + ASSERT(duty <= (uint16_t)*pwm_map[dev].period_reg); + -/** - * Set pwm duty cycle. - * - * \a duty value 0 - 2^16 - */ -void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty) -{ - ASSERT(duty <= (uint16_t)*pwm_map[dev].period_reg); + /* + * If polarity flag is true we must invert + * PWM polarity. + */ + if (pwm_map[dev].pol) + { + duty = (uint16_t)*pwm_map[dev].period_reg - duty; + LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol); + } + /* + * WARNING: is forbidden to write 0 to duty cycle value, + * and so for duty = 0 we must enable PIO and clear output! + */ + if (!duty) + { + PWM_PIO_CODR = pwm_map[dev].pwm_pin; + PWM_PIO_PER = pwm_map[dev].pwm_pin; + pwm_map[dev].duty_zero = true; + } + else + { + PWM_PIO_PDR = pwm_map[dev].pwm_pin; + PWM_PIO_ABSR = pwm_map[dev].pwm_pin; - /* - * If polarity flag is true we must invert - * PWM polarity. + *pwm_map[dev].update_reg = duty; + pwm_map[dev].duty_zero = false; + } + + PWM_ENA = BV(dev); + LOG_INFO("PWM ch[%d] duty[%d], period[%ld]\n", dev, duty, *pwm_map[dev].period_reg); + } + + + /** + * Enable select pwm channel */ - if (pwm_map[dev].pol) + void pwm_hw_enable(PwmDev dev) { - duty = (uint16_t)*pwm_map[dev].period_reg - duty; - LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol); + if (!pwm_map[dev].duty_zero) + { + PWM_PIO_PDR = pwm_map[dev].pwm_pin; + PWM_PIO_ABSR = pwm_map[dev].pwm_pin; + } } - /* - * WARNING: is forbidden to write 0 to duty cycle value, - * and so for duty = 0 we must enable PIO and clear output! + /** + * Disable select pwm channel */ - if (!duty) + void pwm_hw_disable(PwmDev dev) { - PWM_PIO_CODR = pwm_map[dev].pwm_pin; - PWM_PIO_PER = pwm_map[dev].pwm_pin; - pwm_map[dev].duty_zero = true; + PWM_PIO_PER = pwm_map[dev].pwm_pin; } - else - { - PWM_PIO_PDR = pwm_map[dev].pwm_pin; - PWM_PIO_ABSR = pwm_map[dev].pwm_pin; - *pwm_map[dev].update_reg = duty; - pwm_map[dev].duty_zero = false; + /** + * Set PWM polarity to select pwm channel + */ + void pwm_hw_setPolarity(PwmDev dev, bool pol) + { + pwm_map[dev].pol = pol; + LOG_INFO("Set pol[%d]\n", pwm_map[dev].pol); } - PWM_ENA = BV(dev); - LOG_INFO("PWM ch[%d] duty[%d], period[%ld]\n", dev, duty, *pwm_map[dev].period_reg); -} + /** + * Init pwm. + */ + void pwm_hw_init(void) + { + /* + * Init pwm: + * WARNING: is forbidden to write 0 to duty cycle value, + * and so for duty = 0 we must enable PIO and clear output! + * - clear PIO outputs + * - enable PIO outputs + * - Disable PIO and enable PWM functions + * - Power on PWM + */ + PWM_PIO_CODR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); + PWM_PIO_OER = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); + PWM_PIO_PDR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); + PWM_PIO_ABSR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); + PMC_PCER |= BV(PWMC_ID); + + /* Disable all channels. */ + PWM_DIS = 0xFFFFFFFF; + /* Disable prescalers A and B */ + PWM_MR = 0; + + /* + * Set pwm mode: + * - set period alidned to left + * - set output waveform to start at high level + * - allow duty cycle modify at next period event + */ + for (int ch = 0; ch < PWM_CNT; ch++) + { + *pwm_map[ch].mode_reg = 0; + *pwm_map[ch].mode_reg = BV(PWM_CPOL); + } -/** - * Enable select pwm channel - */ -void pwm_hw_enable(PwmDev dev) -{ - if (!pwm_map[dev].duty_zero) - { - PWM_PIO_PDR = pwm_map[dev].pwm_pin; - PWM_PIO_ABSR = pwm_map[dev].pwm_pin; } -} -/** - * Disable select pwm channel - */ -void pwm_hw_disable(PwmDev dev) -{ - PWM_PIO_PER = pwm_map[dev].pwm_pin; -} +#else -/** - * Set PWM polarity to select pwm channel - */ -void pwm_hw_setPolarity(PwmDev dev, bool pol) -{ - pwm_map[dev].pol = pol; - LOG_INFO("Set pol[%d]\n", pwm_map[dev].pol); -} + typedef struct PwmChannelRegs + { + reg32_t CMR; + reg32_t CDTY; + reg32_t CPRD; + reg32_t CCNT; + reg32_t CUPD; + } PwmChannelRegs; -/** - * Init pwm. - */ -void pwm_hw_init(void) -{ /* - * Init pwm: - * WARNING: is forbidden to write 0 to duty cycle value, - * and so for duty = 0 we must enable PIO and clear output! - * - clear PIO outputs - * - enable PIO outputs - * - Disable PIO and enable PWM functions - * - Power on PWM + * Set pwm waveform frequecy. */ - PWM_PIO_CODR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); - PWM_PIO_OER = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); - PWM_PIO_PDR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); - PWM_PIO_ABSR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3); - PMC_PCER |= BV(PWMC_ID); + void pwm_hw_setFrequency(Pwm *ctx, pwm_freq_t freq) + { + uint32_t period = 0; + + for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++) + { + period = CPU_FREQ / (BV(i) * freq); + LOG_INFO("period[%ld], prescale[%d]\n", period, i); + if ((period < PWM_HW_MAX_PERIOD) && (period != 0)) + { + //Clear previous channel prescaler, and set new + ctx->hw->base->CMR &= ~PWM_CPRE_MCK_MASK; + ctx->hw->base->CMR |= i; + //Set pwm period + ATOMIC( + ctx->hw->base->CPRD = period; + ctx->hw->base->CDTY = period; + ); + break; + } + } + + LOG_INFO("PWM ch[%d] period[%ld]\n", ctx->ch, period); + } - /* Disable all channels. */ - PWM_DIS = 0xFFFFFFFF; - /* Disable prescalers A and B */ - PWM_MR = 0; + pwm_hwreg_t pwm_hw_getPeriod(Pwm *ctx) + { + return ctx->hw->base->CPRD; + } /* - * Set pwm mode: - * - set period alidned to left - * - set output waveform to start at high level - * - allow duty cycle modify at next period event + * Set pwm duty cycle. + * + * duty value 0 - (2^16 - 1) */ - for (int ch = 0; ch < PWM_CNT; ch++) + void pwm_hw_setDuty(Pwm *ctx, pwm_hwreg_t hw_duty) { - *pwm_map[ch].mode_reg = 0; - *pwm_map[ch].mode_reg = BV(PWM_CPOL); + ASSERT(hw_duty <= ctx->hw->base->CPRD); + + /* + * WARNING: is forbidden to write 0 or 1 to duty cycle value, + * and so for duty < 2 we must enable PIO and clear output! + */ + if (hw_duty < 2) + { + hw_duty = 2; + PWM_PIO_PER = ctx->hw->pwm_pin; + } + else + PWM_PIO_PDR = ctx->hw->pwm_pin; + + ctx->hw->base->CUPD = hw_duty; + LOG_INFO("PWM ch[%d] duty[%d], period[%ld]\n", ctx->ch, hw_duty, ctx->hw->base->CPRD); } -} + static PwmHardware pwm_channels[] = + { + {//PWM Channel 0 + .pwm_pin = BV(PWM0), + .base = (volatile PwmChannelRegs *)&PWM_CMR0, + }, + {//PWM Channel 1 + .pwm_pin = BV(PWM1), + .base = (volatile PwmChannelRegs *)&PWM_CMR1, + }, + {//PWM Channel 2 + .pwm_pin = BV(PWM2), + .base = (volatile PwmChannelRegs *)&PWM_CMR2, + }, + {//PWM Channel 3 + .pwm_pin = BV(PWM3), + .base = (volatile PwmChannelRegs *)&PWM_CMR3, + }, + }; + + /* + * Init pwm. + */ + void pwm_hw_init(Pwm *ctx, unsigned ch) + { + + ctx->hw = &pwm_channels[ch]; + + /* + * Init pwm: + * - clear PIO outputs + * - enable PIO outputs + * - Enable PWM functions + * - Power on PWM + */ + PWM_PIO_CODR = ctx->hw->pwm_pin; + PWM_PIO_OER = ctx->hw->pwm_pin; + PWM_PIO_PER = ctx->hw->pwm_pin; + PWM_PIO_ABSR = ctx->hw->pwm_pin; + + PMC_PCER |= BV(PWMC_ID); + + /* Disable prescalers A and B */ + PWM_MR = 0; + + /* + * Set pwm mode: + * WARNING: is forbidden to write 0 or 1 to duty cycle value, + * and so for start we set duty to 2. + * Also: + * - set period aligned to left + * - set output waveform to start at high level + * - allow duty cycle modify at next period event + */ + ctx->hw->base->CDTY = 2; + ctx->hw->base->CMR = BV(PWM_CPOL); + PWM_ENA = BV(ch); + } +#endif diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.h b/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.h index 5d36289..403b9f5 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/arm/drv/pwm_at91.h @@ -40,44 +40,64 @@ #ifndef DRV_PWM_AT91_H #define DRV_PWM_AT91_H -#include "hw/pwm_map.h" - #include <cfg/compiler.h> #include <cfg/macros.h> +#include "cfg/cfg_pwm.h" + #include <io/arm.h> +#if CFG_PWM_ENABLE_OLD_API -#define PWM_HW_MAX_PRESCALER_STEP 10 -#define PWM_HW_MAX_PERIOD 0xFFFF + #include "hw/pwm_map.h" -/** - * Type definition for pwm period. - */ -typedef uint16_t pwm_period_t; + /** + * Type definition for pwm period. + */ + typedef uint16_t pwm_period_t; -/** - * Structur definition for pwm driver. - */ -typedef struct PwmChannel -{ - bool duty_zero; ///< True if duty cyle is zero, false otherwise. - bool pol; ///< PWM polarty flag. - int pwm_pin; ///< PWM pin. - reg32_t *mode_reg; ///< PWM mode register. - reg32_t *duty_reg; ///< PWM duty cycle register. - reg32_t *period_reg; ///< PWM periodic register. - reg32_t *update_reg; ///< Update setting register for PWM. - -} PwmChannel; - - -void pwm_hw_init(void); -void pwm_hw_setFrequency(PwmDev dev, uint32_t freq); -void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty); -void pwm_hw_disable(PwmDev dev); -void pwm_hw_enable(PwmDev dev); -void pwm_hw_setPolarity(PwmDev dev, bool pol); -pwm_period_t pwm_hw_getPeriod(PwmDev dev); + /** + * Structur definition for pwm driver. + */ + typedef struct PwmChannel + { + bool duty_zero; ///< True if duty cyle is zero, false otherwise. + bool pol; ///< PWM polarty flag. + int pwm_pin; ///< PWM pin. + reg32_t *mode_reg; ///< PWM mode register. + reg32_t *duty_reg; ///< PWM duty cycle register. + reg32_t *period_reg; ///< PWM periodic register. + reg32_t *update_reg; ///< Update setting register for PWM. + + } PwmChannel; + + + void pwm_hw_init(void); + void pwm_hw_setFrequency(PwmDev dev, uint32_t freq); + void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty); + void pwm_hw_disable(PwmDev dev); + void pwm_hw_enable(PwmDev dev); + void pwm_hw_setPolarity(PwmDev dev, bool pol); + pwm_period_t pwm_hw_getPeriod(PwmDev dev); + +#else + #include <drv/pwm.h> + + typedef uint16_t pwm_hwreg_t; + + struct PwmChannelRegs; //fwd decl + + typedef struct PwmHardware + { + uint32_t pwm_pin; ///< PWM pin. + volatile struct PwmChannelRegs *base; + } PwmHardware; + + pwm_hwreg_t pwm_hw_getPeriod(Pwm *ctx); + void pwm_hw_setFrequency(struct Pwm *ctx, pwm_freq_t freq); + void pwm_hw_setDuty(Pwm *ctx, pwm_hwreg_t duty); + void pwm_hw_init(struct Pwm *ctx, unsigned ch); + +#endif #endif /* DRV_ADC_AT91_H */ diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/kdebug_avr.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/kdebug_avr.c index 8fa1a4b..e5718c9 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/kdebug_avr.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/kdebug_avr.c @@ -355,6 +355,7 @@ INLINE void kdbg_hw_init(void) #if CONFIG_KDEBUG_PORT == 0 UBRR0H = (uint8_t)(period>>8); UBRR0L = (uint8_t)period; + UCSR0A = 0; /* The Arduino Uno bootloader turns on U2X0 */ KDBG_UART0_BUS_INIT; #else #error Only CONFIG_KDEBUG_PORT 0 is supported for this cpu diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/ser_avr.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/ser_avr.c index 7f8cf93..ce44fd1 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/ser_avr.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/avr/drv/ser_avr.c @@ -146,6 +146,7 @@ * - Enable only the RX complete interrupt */ #define SER_UART0_BUS_TXINIT do { \ + UCSR0A = 0; /* The Arduino Uno bootloader turns on U2X0 */ \ UCSR0B = BV(BIT_RXCIE0) | BV(BIT_RXEN0) | BV(BIT_TXEN0); \ } while (0) #endif @@ -457,7 +458,20 @@ struct AvrSerial volatile bool sending; }; +static uint16_t uart_period(unsigned long bps) +{ + uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, bps) - 1; + + #ifdef _DEBUG + long skew = bps - (long)(period + 1) * (CPU_FREQ / 16); + /* 8N1 is reliable within 3% skew */ + if ((unsigned long)ABS(skew) > bps / (100 / 3)) + kprintf("Baudrate off by %ldbps\n", skew); + #endif + //DB(kprintf("uart_period(bps=%lu): period=%u\n", bps, period);) + return period; +} /* * Callbacks @@ -494,15 +508,12 @@ static void uart0_enabletxirq(struct SerialHardware *_hw) static void uart0_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) { - /* Compute baud-rate period */ - uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, rate) - 1; + uint16_t period = uart_period(rate); #if !CPU_AVR_ATMEGA103 - UBRR0H = (period) >> 8; + UBRR0H = period >> 8; #endif - UBRR0L = (period); - - //DB(kprintf("uart0_setbaudrate(rate=%lu): period=%d\n", rate, period);) + UBRR0L = period; } static void uart0_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) @@ -547,13 +558,9 @@ static void uart1_enabletxirq(struct SerialHardware *_hw) static void uart1_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) { - /* Compute baud-rate period */ - uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, rate) - 1; - - UBRR1H = (period) >> 8; - UBRR1L = (period); - - //DB(kprintf("uart1_setbaudrate(rate=%ld): period=%d\n", rate, period);) + uint16_t period = uart_period(rate); + UBRR1H = period >> 8; + UBRR1L = period; } static void uart1_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) @@ -598,13 +605,9 @@ static void uart2_enabletxirq(struct SerialHardware *_hw) static void uart2_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) { - /* Compute baud-rate period */ - uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, rate) - 1; - - UBRR2H = (period) >> 8; - UBRR2L = (period); - - //DB(kprintf("uart2_setbaudrate(rate=%ld): period=%d\n", rate, period);) + uint16_t period = uart_period(rate); + UBRR2H = period >> 8; + UBRR2L = period; } static void uart2_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) @@ -649,13 +652,9 @@ static void uart3_enabletxirq(struct SerialHardware *_hw) static void uart3_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) { - /* Compute baud-rate period */ - uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, rate) - 1; - - UBRR3H = (period) >> 8; - UBRR3L = (period); - - //DB(kprintf("uart3_setbaudrate(rate=%ld): period=%d\n", rate, period);) + uint16_t period = uart_period(rate); + UBRR3H = period >> 8; + UBRR3L = period; } static void uart3_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/adc_cm3.h b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/adc_cm3.h index b9987e4..168a5da 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/adc_cm3.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/adc_cm3.h @@ -42,6 +42,8 @@ #include "adc_lm3s.h" #elif CPU_CM3_STM32 #include "adc_stm32.h" +#elif CPU_CM3_SAM3X + #include "adc_sam3.h" /*#elif Add other ARM families here */ #else #error Unknown CPU diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c index 8f7f194..494c68e 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c @@ -33,6 +33,8 @@ * \brief CAN hardware-specific implementation * * \author Nicolas Dandrimont <Nic...@cr...> + * + * $WIZ$ */ #include "can_stm32.h" @@ -52,6 +54,7 @@ #include <cfg/log.h> #include <drv/can.h> +#include <drv/timer.h> #include <drv/clock_stm32.h> #include <drv/gpio_stm32.h> @@ -62,6 +65,16 @@ #include <drv/irq_cm3.h> +/** + * CAN Remapping values for STM32 + * + * $WIZ$ can_stm32_remaps = "CAN_STM32_PORTA", "CAN_STM32_PORTB", "CAN_STM32_PORTD" + * \{ + */ +#define CAN_STM32_PORTA 0 +#define CAN_STM32_PORTB 1 +#define CAN_STM32_PORTD 2 +/* \} */ static can_driver _cand1; can_driver *CAND1 = &_cand1; @@ -139,11 +152,33 @@ void can_hw_init(void) // Enable the clocks RCC->APB2ENR |= RCC_APB2_AFIO; + +#if CAN_STM32_REMAP == CAN_STM32_PORTA RCC->APB2ENR |= RCC_APB2_GPIOA; +#elif CAN_STM32_REMAP == CAN_STM32_PORTB + RCC->APB2ENR |= RCC_APB2_GPIOB; +#elif CAN_STM32_REMAP == CAN_STM32_PORTD + RCC->APB2ENR |= RCC_APB2_GPIOD; +#else + #error "CAN remapping not supported for stm32" +#endif // Set the pins to the right mode for CAN. - stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, BV(11), GPIO_MODE_IN_FLOATING, GPIO_SPEED_10MHZ); +#if CAN_STM32_REMAP == CAN_STM32_PORTA + stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, BV(11), GPIO_MODE_IPU, GPIO_SPEED_50MHZ); stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, BV(12), GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); +#elif CAN_STM32_REMAP == CAN_STM32_PORTB + stm32_gpioRemap(GPIO_REMAP1_CAN1, GPIO_REMAP_ENABLE); + stm32_gpioPinConfig((struct stm32_gpio *)GPIOB_BASE, BV(8), GPIO_MODE_IPU, GPIO_SPEED_50MHZ); + stm32_gpioPinConfig((struct stm32_gpio *)GPIOB_BASE, BV(9), GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); +#elif CAN_STM32_REMAP == CAN_STM32_PORTD + stm32_gpioRemap(GPIO_REMAP2_CAN1, GPIO_REMAP_ENABLE); + stm32_gpioPinConfig((struct stm32_gpio *)GPIOD_BASE, BV(0), GPIO_MODE_IPU, GPIO_SPEED_50MHZ); + stm32_gpioPinConfig((struct stm32_gpio *)GPIOD_BASE, BV(1), GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); +#else + #error "CAN remapping not supported for stm32" +#endif + } void can_hw_start(can_driver *drv) { diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.c new file mode 100644 index 0000000..889a5c1 --- /dev/null +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.c @@ -0,0 +1,512 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2010,2011 Develer S.r.l. (http://www.develer.com/) + * All Rights Reserved. + * --> + * + * \brief EMAC driver for AT91SAM family with Davicom 9161A phy. + * + * \author Daniele Basile <as...@de...> + * \author Andrea Righi <ar...@de...> + * \author Stefano Fedrigo <al...@de...> + */ + +#include "cfg/cfg_eth.h" + +#define LOG_LEVEL ETH_LOG_LEVEL +#define LOG_FORMAT ETH_LOG_FORMAT + +#include <cfg/log.h> + +#include <cfg/debug.h> +#include <cfg/log.h> +#include <cfg/macros.h> +#include <cfg/compiler.h> + +// TODO: unify includes +//#include <io/at91sam7.h> +//#include <io/arm.h> +//#include <io/include.h> +#include <io/sam3.h> +#include <drv/irq_cm3.h> + +#include <cpu/power.h> +#include <cpu/types.h> +#include <cpu/irq.h> + +#include <drv/timer.h> +#include <drv/eth.h> + +#include <mware/event.h> + +#include <string.h> + +#include "eth_sam3.h" + +#define EMAC_RX_INTS (BV(EMAC_RCOMP) | BV(EMAC_ROVR) | BV(EMAC_RXUBR)) +#define EMAC_TX_INTS (BV(EMAC_TCOMP) | BV(EMAC_TXUBR) | BV(EMAC_RLEX)) + +/* + * MAC address configuration (please change this in your project!). + * + * TODO: make this paramater user-configurable from the Wizard. + */ +const uint8_t mac_addr[] = { 0x00, 0x23, 0x54, 0x6a, 0x77, 0x55 }; + +/* Silent Doxygen bug... */ +#ifndef __doxygen__ +/* + * NOTE: this buffer should be declared as 'volatile' because it is read by the + * hardware. However, this is accessed only via memcpy() that should guarantee + * coherency when copying from/to buffers. + */ +static uint8_t tx_buf[EMAC_TX_BUFFERS * EMAC_TX_BUFSIZ] ALIGNED(8); +static volatile BufDescriptor tx_buf_tab[EMAC_TX_DESCRIPTORS] ALIGNED(8); + +/* + * NOTE: this buffer should be declared as 'volatile' because it is wrote by + * the hardware. However, this is accessed only via memcpy() that should + * guarantee coherency when copying from/to buffers. + */ +static uint8_t rx_buf[EMAC_RX_BUFFERS * EMAC_RX_BUFSIZ] ALIGNED(8); +static volatile BufDescriptor rx_buf_tab[EMAC_RX_DESCRIPTORS] ALIGNED(8); +#endif + +static int tx_buf_idx; +static int tx_buf_offset; +static int rx_buf_idx; + +static Event recv_wait, send_wait; + +static DECLARE_ISR(emac_irqHandler) +{ + /* Read interrupt status and disable interrupts. */ + uint32_t isr = EMAC_ISR; + + kprintf("irq: %x\n", isr); + + /* Receiver interrupt */ + if ((isr & EMAC_RX_INTS)) + { + kprintf("emac: rx %x\n", isr); + if (isr & BV(EMAC_RCOMP)) + event_do(&recv_wait); + EMAC_RSR = EMAC_RX_INTS; + } + /* Transmitter interrupt */ + if (isr & EMAC_TX_INTS) + { + if (isr & BV(EMAC_TCOMP)) + { + kprintf("emac: tcomp\n"); + event_do(&send_wait); + } + if (isr & BV(EMAC_RLEX)) + kprintf("emac: rlex\n"); + EMAC_TSR = EMAC_TX_INTS; + } + //AIC_EOICR = 0; +} + +/* + * \brief Read contents of PHY register. + * + * \param reg PHY register number. + * + * \return Contents of the specified register. + */ +static uint16_t phy_hw_read(reg8_t reg) +{ + // PHY read command. + EMAC_MAN = EMAC_SOF | EMAC_RW_READ | (NIC_PHY_ADDR << EMAC_PHYA_SHIFT) + | ((reg << EMAC_REGA_SHIFT) & EMAC_REGA) | EMAC_CODE; + + // Wait until PHY logic completed. + while (!(EMAC_NSR & BV(EMAC_IDLE))) + cpu_relax(); + + // Get data from PHY maintenance register. + return (uint16_t)(EMAC_MAN & EMAC_DATA); +} + +/* + * \brief Write value to PHY register. + * + * \param reg PHY register number. + * \param val Value to write. + */ +static void phy_hw_write(reg8_t reg, uint16_t val) +{ + // PHY write command. + EMAC_MAN = EMAC_SOF | EMAC_RW_WRITE | (NIC_PHY_ADDR << EMAC_PHYA_SHIFT) + | ((reg << EMAC_REGA_SHIFT) & EMAC_REGA) | EMAC_CODE | val; + + // Wait until PHY logic completed. + while (!(EMAC_NSR & BV(EMAC_IDLE))) + cpu_relax(); +} + +static int emac_reset(void) +{ + uint16_t phy_cr; + + // Enable devices + //PMC_PCER = BV(PIOA_ID); + //PMC_PCER = BV(PIOB_ID); + //PMC_PCER = BV(EMAC_ID); + // TOOD: Implement in sam7x + pmc_periphEnable(PIOA_ID); + pmc_periphEnable(PIOB_ID); + pmc_periphEnable(EMAC_ID); + + // Disable TESTMODE + PIOB_PUDR = BV(PHY_RXDV_TESTMODE_BIT); +#if CPU_ARM_AT91 + // Disable RMII + PIOB_PUDR = BV(PHY_COL_RMII_BIT); + + // Disable PHY power down. + PIOB_PER = BV(PHY_PWRDN_BIT); + PIOB_OER = BV(PHY_PWRDN_BIT); + PIOB_CODR = BV(PHY_PWRDN_BIT); +#endif + + // Toggle external hardware reset pin. + RSTC_MR = RSTC_KEY | (1 << RSTC_ERSTL_SHIFT) | BV(RSTC_URSTEN); + RSTC_CR = RSTC_KEY | BV(RSTC_EXTRST); + + while ((RSTC_SR & BV(RSTC_NRSTL)) == 0) + cpu_relax(); + + // Configure MII ports. +#if CPU_ARM_AT91 + PIOB_ASR = PHY_MII_PINS; + PIOB_BSR = 0; + PIOB_PDR = PHY_MII_PINS; + // Enable receive and transmit clocks. + EMAC_USRIO = BV(EMAC_CLKEN); +#else + PIO_PERIPH_SEL(PIOB_BASE, PHY_MII_PINS, PIO_PERIPH_A); + PIOB_PDR = PHY_MII_PINS; + // Enable receive, transmit clocks and RMII mode. + EMAC_USRIO = BV(EMAC_CLKEN) | BV(EMAC_RMII); +#endif + + // Enable management port. + EMAC_NCR |= BV(EMAC_MPE); + EMAC_NCFGR |= EMAC_CLK_HCLK_32; + + // Set local MAC address. + EMAC_SA1L = (mac_addr[3] << 24) | (mac_addr[2] << 16) | + (mac_addr[1] << 8) | mac_addr[0]; + EMAC_SA1H = (mac_addr[5] << 8) | mac_addr[4]; + + // Wait for PHY ready + timer_delay(255); + + // Clear MII isolate. + phy_hw_read(NIC_PHY_BMCR); + phy_cr = phy_hw_read(NIC_PHY_BMCR); + + phy_cr &= ~NIC_PHY_BMCR_ISOLATE; + phy_hw_write(NIC_PHY_BMCR, phy_cr); + + phy_cr = phy_hw_read(NIC_PHY_BMCR); + + LOG_INFO("%s: PHY ID %#04x %#04x\n", + __func__, + phy_hw_read(NIC_PHY_ID1), phy_hw_read(NIC_PHY_ID2)); + + // Wait for auto negotiation completed. + phy_hw_read(NIC_PHY_BMSR); + for (;;) + { + if (phy_hw_read(NIC_PHY_BMSR) & NIC_PHY_BMSR_ANCOMPL) + break; + cpu_relax(); + } + + // Disable management port. + EMAC_NCR &= ~BV(EMAC_MPE); + + return 0; +} + +static int emac_start(void) +{ + uint32_t addr; + int i; + + for (i = 0; i < EMAC_RX_DESCRIPTORS; i++) + { + addr = (uint32_t)(rx_buf + (i * EMAC_RX_BUFSIZ)); + rx_buf_tab[i].addr = addr & BUF_ADDRMASK; + } + rx_buf_tab[EMAC_RX_DESCRIPTORS - 1].addr |= RXBUF_WRAP; + + for (i = 0; i < EMAC_TX_DESCRIPTORS; i++) + { + addr = (uint32_t)(tx_buf + (i * EMAC_TX_BUFSIZ)); + tx_buf_tab[i].addr = addr & BUF_ADDRMASK; + tx_buf_tab[i].stat = TXS_USED; + } + tx_buf_tab[EMAC_TX_DESCRIPTORS - 1].stat = TXS_USED | TXS_WRAP; + + /* Tell the EMAC where to find the descriptors. */ + EMAC_RBQP = (uint32_t)rx_buf_tab; + EMAC_TBQP = (uint32_t)tx_buf_tab; + + /* Clear receiver status. */ + EMAC_RSR = BV(EMAC_OVR) | BV(EMAC_REC) | BV(EMAC_BNA); + + /* Copy all frames and discard FCS. */ + EMAC_NCFGR |= BV(EMAC_CAF) | BV(EMAC_DRFCS); + + /* Enable receiver, transmitter and statistics. */ + EMAC_NCR |= BV(EMAC_TE) | BV(EMAC_RE) | BV(EMAC_WESTAT); + + return 0; +} + +ssize_t eth_putFrame(const uint8_t *buf, size_t len) +{ + size_t wr_len; + + if (UNLIKELY(!len)) + return -1; + ASSERT(len <= sizeof(tx_buf)); + + /* Check if the transmit buffer is available */ + while (!(tx_buf_tab[tx_buf_idx].stat & TXS_USED)) + event_wait(&send_wait); + + /* Copy the data into the buffer and prepare descriptor */ + wr_len = MIN(len, (size_t)EMAC_TX_BUFSIZ - tx_buf_offset); + memcpy((uint8_t *)tx_buf_tab[tx_buf_idx].addr + tx_buf_offset, + buf, wr_len); + tx_buf_offset += wr_len; + + return wr_len; +} + +void eth_sendFrame(void) +{ + tx_buf_tab[tx_buf_idx].stat = (tx_buf_offset & TXS_LENGTH_FRAME) | + TXS_LAST_BUFF | + ((tx_buf_idx == EMAC_TX_DESCRIPTORS - 1) ? TXS_WRAP : 0); + EMAC_NCR |= BV(EMAC_TSTART); + + tx_buf_offset = 0; + if (++tx_buf_idx >= EMAC_TX_DESCRIPTORS) + tx_buf_idx = 0; +} + +ssize_t eth_send(const uint8_t *buf, size_t len) + { + if (UNLIKELY(!len)) + return -1; + + len = eth_putFrame(buf, len); + eth_sendFrame(); + + return len; +} + +static void eth_buf_realign(int idx) +{ + /* Empty buffer found. Realign. */ + do { + rx_buf_tab[rx_buf_idx].addr &= ~RXBUF_OWNERSHIP; + if (++rx_buf_idx >= EMAC_RX_BUFFERS) + rx_buf_idx = 0; + } while (idx != rx_buf_idx); +} + +static size_t __eth_getFrameLen(void) +{ + int idx, n = EMAC_RX_BUFFERS; + +skip: + /* Skip empty buffers */ + while ((n > 0) && !(rx_buf_tab[rx_buf_idx].addr & RXBUF_OWNERSHIP)) + { + if (++rx_buf_idx >= EMAC_RX_BUFFERS) + rx_buf_idx = 0; + n--; + } + if (UNLIKELY(!n)) + { + LOG_INFO("no frame found\n"); + return 0; + } + /* Search the start of frame and cleanup fragments */ + while ((n > 0) && (rx_buf_tab[rx_buf_idx].addr & RXBUF_OWNERSHIP) && + !(rx_buf_tab[rx_buf_idx].stat & RXS_SOF)) + { + rx_buf_tab[rx_buf_idx].addr &= ~RXBUF_OWNERSHIP; + if (++rx_buf_idx >= EMAC_RX_BUFFERS) + rx_buf_idx = 0; + n--; + } + if (UNLIKELY(!n)) + { + LOG_INFO("no SOF found\n"); + return 0; + } + /* Search end of frame to evaluate the total frame size */ + idx = rx_buf_idx; +restart: + while (n > 0) + { + if (UNLIKELY(!(rx_buf_tab[idx].addr & RXBUF_OWNERSHIP))) + { + /* Empty buffer found. Realign. */ + eth_buf_realign(idx); + goto skip; + } + if (rx_buf_tab[idx].stat & RXS_EOF) + return rx_buf_tab[idx].stat & RXS_LENGTH_FRAME; + if (UNLIKELY((idx != rx_buf_idx) && + (rx_buf_tab[idx].stat & RXS_SOF))) + { + /* Another start of frame found. Realign. */ + eth_buf_realign(idx); + goto restart; + } + if (++idx >= EMAC_RX_BUFFERS) + idx = 0; + n--; + } + LOG_INFO("no EOF found\n"); + return 0; +} + +size_t eth_getFrameLen(void) +{ + size_t len; + + /* Check if there is at least one available frame in the buffer */ + while (1) + { + len = __eth_getFrameLen(); + if (LIKELY(len)) + break; + /* Wait for RX interrupt */ + event_wait(&recv_wait); + } + return len; +} + +ssize_t eth_getFrame(uint8_t *buf, size_t len) +{ + uint8_t *addr; + size_t rd_len = 0; + + if (UNLIKELY(!len)) + return -1; + ASSERT(len <= sizeof(rx_buf)); + + /* Copy data from the RX buffer */ + addr = (uint8_t *)(rx_buf_tab[rx_buf_idx].addr & BUF_ADDRMASK); + if (addr + len > &rx_buf[countof(rx_buf)]) + { + size_t count = &rx_buf[countof(rx_buf)] - addr; + + memcpy(buf, addr, count); + memcpy(buf + count, rx_buf, len - count); + } + else + { + memcpy(buf, addr, len); + } + /* Update descriptors */ + while (rd_len < len) + { + if (len - rd_len >= EMAC_RX_BUFSIZ) + rd_len += EMAC_RX_BUFSIZ; + else + rd_len += len - rd_len; + if (UNLIKELY(!(rx_buf_tab[rx_buf_idx].addr & RXBUF_OWNERSHIP))) + { + LOG_INFO("bad frame found\n"); + return 0; + } + rx_buf_tab[rx_buf_idx].addr &= ~RXBUF_OWNERSHIP; + if (++rx_buf_idx >= EMAC_RX_DESCRIPTORS) + rx_buf_idx = 0; + } + + return rd_len; +} + +ssize_t eth_recv(uint8_t *buf, size_t len) +{ + if (UNLIKELY(!len)) + return -1; + len = MIN(len, eth_getFrameLen()); + return len ? eth_getFrame(buf, len) : 0; +} + +int eth_init() +{ + cpu_flags_t flags; + + emac_reset(); + emac_start(); + + event_initGeneric(&recv_wait); + event_initGeneric(&send_wait); + + // Register interrupt vector + IRQ_SAVE_DISABLE(flags); + + /* Disable all emac interrupts */ + EMAC_IDR = 0xFFFFFFFF; + +#if CPU_ARM_AT91 + // TODO: define sysirq_set... + /* Set the vector. */ + AIC_SVR(EMAC_ID) = emac_irqHandler; + /* Initialize to edge triggered with defined priority. */ + AIC_SMR(EMAC_ID) = AIC_SRCTYPE_INT_EDGE_TRIGGERED; + /* Clear pending interrupt */ + AIC_ICCR = BV(EMAC_ID); + /* Enable the system IRQ */ + AIC_IECR = BV(EMAC_ID); +#else + sysirq_setHandler(INT_EMAC, emac_irqHandler); +#endif + + /* Enable interrupts */ + EMAC_IER = EMAC_RX_INTS | EMAC_TX_INTS; + + IRQ_RESTORE(flags); + + return 0; +} diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.h b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.h new file mode 100644 index 0000000..f733df9 --- /dev/null +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/eth_sam3.h @@ -0,0 +1,208 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2009,2010,2011 Develer S.r.l. (http://www.develer.com/) + * All Rights Reserved. + * --> + * + * \brief EMAC driver for AT91SAM family with Davicom 9161A phy, interface. + * + * \author Daniele Basile <as...@de...> + * \author Andrea Righi <ar...@de...> + * \author Stefano Fedrigo <al...@de...> + */ + +#ifndef ETH_SAM3_H +#define ETH_SAM3_H + +// Settings and definition for DAVICOM 9161A +// \{ +#define NIC_PHY_ADDR 31 + +//Registry definition +#define NIC_PHY_BMCR 0x00 // Basic mode control register. +#define NIC_PHY_BMCR_COLTEST 0x0080 // Collision test. +#define NIC_PHY_BMCR_FDUPLEX 0x0100 // Full duplex mode. +#define NIC_PHY_BMCR_ANEGSTART 0x0200 // Restart auto negotiation. +#define NIC_PHY_BMCR_ISOLATE 0x0400 // Isolate from MII. +#define NIC_PHY_BMCR_PWRDN 0x0800 // Power-down. +#define NIC_PHY_BMCR_ANEGENA 0x1000 // Enable auto negotiation. +#define NIC_PHY_BMCR_100MBPS 0x2000 // Select 100 Mbps. +#define NIC_PHY_BMCR_LOOPBACK 0x4000 // Enable loopback mode. +#define NIC_PHY_BMCR_RESET 0x8000 // Software reset. + +#define NIC_PHY_BMSR 0x01 // Basic mode status register. +#define NIC_PHY_BMSR_ANCOMPL 0x0020 // Auto negotiation complete. +#define NIC_PHY_BMSR_ANEGCAPABLE 0x0008 // Able to do auto-negotiation +#define NIC_PHY_BMSR_LINKSTAT 0x0004 // Link status. + +#define NIC_PHY_ID1 0x02 // PHY identifier register 1. +#define NIC_PHY_ID2 0x03 // PHY identifier register 2. +#define NIC_PHY_ANAR 0x04 // Auto negotiation advertisement register. +#define NIC_PHY_ANLPAR 0x05 // Auto negotiation link partner availability register. +#define NIC_PHY_ANER 0x06 // Auto negotiation expansion register. + +#if CPU_ARM_AT91 + +/* + * Pin definition for DAVICOM 9161A. + * See schematics for AT91SAM7X-EK evalution board. + */ +// All pins in port B +#define PHY_TXCLK_ISOLATE_BIT 0 +#define PHY_REFCLK_XT2_BIT 0 +#define PHY_TXEN_BIT 1 +#define PHY_TXD0_BIT 2 +#define PHY_TXD1_BIT 3 +#define PHY_CRS_AD4_BIT 4 +#define PHY_RXD0_AD0_BIT 5 +#define PHY_RXD1_AD1_BIT 6 +#define PHY_RXER_RXD4_RPTR_BIT 7 +#define PHY_MDC_BIT 8 +#define PHY_MDIO_BIT 9 +#define PHY_TXD2_BIT 10 +#define PHY_TXD3_BIT 11 +#define PHY_TXER_TXD4_BIT 12 +#define PHY_RXD2_AD2_BIT 13 +#define PHY_RXD3_AD3_BIT 14 +#define PHY_RXDV_TESTMODE_BIT 15 +#define PHY_COL_RMII_BIT 16 +#define PHY_RXCLK_10BTSER_BIT 17 +#define PHY_PWRDN_BIT 18 +#define PHY_MDINTR_BIT 26 + +#define PHY_MII_PINS \ + BV(PHY_REFCLK_XT2_BIT) \ + | BV(PHY_TXEN_BIT) \ + | BV(PHY_TXD0_BIT) \ + | BV(PHY_TXD1_BIT) \ + | BV(PHY_CRS_AD4_BIT) \ + | BV(PHY_RXD0_AD0_BIT) \ + | BV(PHY_RXD1_AD1_BIT) \ + | BV(PHY_RXER_RXD4_RPTR_BIT) \ + | BV(PHY_MDC_BIT) \ + | BV(PHY_MDIO_BIT) \ + | BV(PHY_TXD2_BIT) \ + | BV(PHY_TXD3_BIT) \ + | BV(PHY_TXER_TXD4_BIT) \ + | BV(PHY_RXD2_AD2_BIT) \ + | BV(PHY_RXD3_AD3_BIT) \ + | BV(PHY_RXDV_TESTMODE_BIT) \ + | BV(PHY_COL_RMII_BIT) \ + | BV(PHY_RXCLK_10BTSER_BIT) + +#else + +/* + * Pin definition for DAVICOM 9161A. + * See schematics for SAM3X-EK evalution board. + */ +// Port B +#define PHY_TXCLK_ISOLATE_BIT 0 +#define PHY_REFCLK_XT2_BIT 0 +#define PHY_TXEN_BIT 1 +#define PHY_TXD0_BIT 2 +#define PHY_TXD1_BIT 3 +#define PHY_RXDV_TESTMODE_BIT 4 +#define PHY_RXD0_AD0_BIT 5 +#define PHY_RXD1_AD1_BIT 6 +#define PHY_RXER_RXD4_RPTR_BIT 7 +#define PHY_MDC_BIT 8 +#define PHY_MDIO_BIT 9 +// Port A +#define PHY_MDINTR_BIT 5 + +#define PHY_MII_PINS \ + BV(PHY_REFCLK_XT2_BIT) \ + | BV(PHY_TXEN_BIT) \ + | BV(PHY_TXD0_BIT) \ + | BV(PHY_TXD1_BIT) \ + | BV(PHY_RXDV_TESTMODE_BIT) \ + | BV(PHY_RXD0_AD0_BIT) \ + | BV(PHY_RXD1_AD1_BIT) \ + | BV(PHY_RXER_RXD4_RPTR_BIT) \ + | BV(PHY_MDC_BIT) \ + | BV(PHY_MDIO_BIT) + +#endif /* CPU_ARM_AT91 */ +// \} + + +#define EMAC_TX_BUFSIZ 1518 //!!! Don't change this +#define EMAC_TX_BUFFERS 1 //!!! Don't change this +#define EMAC_TX_DESCRIPTORS EMAC_TX_BUFFERS + +#define EMAC_RX_BUFFERS 32 //!!! Don't change this +#define EMAC_RX_BUFSIZ 128 //!!! Don't change this +#define EMAC_RX_DESCRIPTORS EMAC_RX_BUFFERS + +// Flag to manage local tx buffer +#define TXS_USED 0x80000000 //Used buffer. +#define TXS_WRAP 0x40000000 //Last descriptor. +#define TXS_ERROR 0x20000000 //Retry limit exceeded. +#define TXS_UNDERRUN 0x10000000 //Transmit underrun. +#define TXS_NO_BUFFER 0x08000000 //Buffer exhausted. +#define TXS_NO_CRC 0x00010000 //CRC not appended. +#define TXS_LAST_BUFF 0x00008000 //Last buffer of frame. +#define TXS_LENGTH_FRAME 0x000007FF // Length of frame including FCS. + +// Flag to manage local rx buffer +#define RXBUF_OWNERSHIP 0x00000001 +#define RXBUF_WRAP 0x00000002 + +#define BUF_ADDRMASK 0xFFFFFFFC + +#define RXS_BROADCAST_ADDR 0x80000000 // Broadcast address detected. +#define RXS_MULTICAST_HASH 0x40000000 // Multicast hash match. +#define RXS_UNICAST_HASH 0x20000000 // Unicast hash match. +#define RXS_EXTERNAL_ADDR 0x10000000 // External address match. +#define RXS_SA1_ADDR 0x04000000 // Specific address register 1 match. +#define RXS_SA2_ADDR 0x02000000 // Specific address register 2 match. +#define RXS_SA3_ADDR 0x01000000 // Specific address register 3 match. +#define RXS_SA4_ADDR 0x00800000 // Specific address register 4 match. +#define RXS_TYPE_ID 0x00400000 // Type ID match. +#define RXS_VLAN_TAG 0x00200000 // VLAN tag detected. +#define RXS_PRIORITY_TAG 0x00100000 // Priority tag detected. +#define RXS_VLAN_PRIORITY 0x000E0000 // VLAN priority. +#define RXS_CFI_IND 0x00010000 // Concatenation format indicator. +#define RXS_EOF 0x00008000 // End of frame. +#define RXS_SOF 0x00004000 // Start of frame. +#define RXS_RBF_OFFSET 0x00003000 // Receive buffer offset mask. +#define RXS_LENGTH_FRAME 0x000007FF // Length of frame including FCS. + +#define EMAC_RSR_BITS (BV(EMAC_BNA) | BV(EMAC_REC) | BV(EMAC_OVR)) +#define EMAC_TSR_BITS (BV(EMAC_UBR) | BV(EMAC_COL) | BV(EMAC_RLES) | \ + BV(EMAC_BEX) | BV(EMAC_COMP) | BV(EMAC_UND)) + +typedef struct BufDescriptor +{ + volatile uint32_t addr; + volatile uint32_t stat; +} BufDescriptor; + +#endif /* ETH_SAM3_H */ diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/flash_stm32.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/flash_stm32.c index 816cdd5..d92e914 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/flash_stm32.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/flash_stm32.c @@ -67,6 +67,7 @@ static bool flash_wait(struct KBlock *blk) ticks_t start = timer_clock(); while (true) { + cpu_relax(); if (!(EMB_FLASH->SR & FLASH_FLAG_BSY)) break; @@ -90,8 +91,6 @@ static bool flash_wait(struct KBlock *blk) LOG_ERR("Timeout..\n"); return false; } - - cpu_relax(); } return true; diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/kdebug_stm32.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/kdebug_stm32.c index 646d37f..a60d19e 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/kdebug_stm32.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/kdebug_stm32.c @@ -77,10 +77,9 @@ INLINE void kdbg_hw_init(void) RCC->APB2ENR |= RCC_APB2_AFIO; /* Configure USART pins */ #if CONFIG_KDEBUG_PORT == 0 - RCC->APB2ENR |= RCC_APB2_GPIOB; + RCC->APB2ENR |= RCC_APB2_GPIOA; RCC->APB2ENR |= RCC_APB2_USART1; - stm32_gpioRemap(GPIO_REMAP_USART1, GPIO_REMAP_ENABLE); - stm32_gpioPinConfig((struct stm32_gpio *)GPIOB_BASE, GPIO_USART1_TX_PIN, + stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, GPIO_USART1_TX_PIN, GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); #elif CONFIG_KDEBUG_PORT == 1 RCC->APB2ENR |= RCC_APB2_GPIOA; diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/usb_stm32.c b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/usb_stm32.c index 46069ff..393b3cc 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -1123,7 +1123,8 @@ static void usb_endpointRead_complete(int ep) rx_size = ep_cnfg[ep].size; } -ssize_t usb_endpointRead(int ep, void *buffer, ssize_t size) +ssize_t usb_endpointReadTimeout(int ep, void *buffer, ssize_t size, + ticks_t timeout) { int ep_num = usb_ep_logical_to_hw(ep); ssize_t max_size = sizeof(ep_buffer[ep_num]); @@ -1158,7 +1159,11 @@ ssize_t usb_endpointRead(int ep, void *buffer, ssize_t size) /* Blocking read */ __usb_ep_read(ep_num, ep_buffer[ep_num], size, usb_endpointRead_complete); - event_wait(&usb_event_done[ep_num >> 1]); + if (timeout < 0) + event_wait(&usb_event_done[ep_num >> 1]); + else + if (!event_waitTimeout(&usb_event_done[ep_num >> 1], timeout)) + return 0; memcpy(buffer, ep_buffer[ep_num], rx_size); return rx_size; @@ -1177,7 +1182,8 @@ static void usb_endpointWrite_complete(int ep) tx_size = ep_cnfg[ep].size; } -ssize_t usb_endpointWrite(int ep, const void *buffer, ssize_t size) +ssize_t usb_endpointWriteTimeout(int ep, const void *buffer, ssize_t size, + ticks_t timeout) { int ep_num = usb_ep_logical_to_hw(ep); ssize_t max_size = sizeof(ep_buffer[ep_num]); @@ -1213,7 +1219,11 @@ ssize_t usb_endpointWrite(int ep, const void *buffer, ssize_t size) memcpy(ep_buffer[ep_num], buffer, size); __usb_ep_write(ep_num, ep_buffer[ep_num], size, usb_endpointWrite_complete); - event_wait(&usb_event_done[ep_num >> 1]); + if (timeout < 0) + event_wait(&usb_event_done[ep_num >> 1]); + else + if (!event_waitTimeout(&usb_event_done[ep_num >> 1], timeout)) + return 0; return tx_size; } diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3.h b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3.h index ef5efa0..9437c61 100644 --- a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3.h +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3.h @@ -158,6 +158,7 @@ #include "sam3_sysctl.h" #include "sam3_pmc.h" #include "sam3_smc.h" +#include "sam3_sdramc.h" #include "sam3_ints.h" #include "sam3_pio.h" #include "sam3_nvic.h" @@ -166,6 +167,9 @@ #include "sam3_spi.h" #include "sam3_flash.h" #include "sam3_wdt.h" +#include "sam3_emac.h" +#include "sam3_rstc.h" +#include "sam3_adc.h" /** * U(S)ART I/O pins diff --git a/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3_adc.h b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3_adc.h new file mode 100644 index 0000000..2545f23 --- /dev/null +++ b/elec/boards/USB_CAN/Firmware/bertos/cpu/cortex-m3/io/sam3_adc.h @@ -0,0 +1,200 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2011 Develer S.r.l. (http://www.develer.com/) + * + * --> + * + * \author Daniele Basile <as...@de...> + * + * SAM3 Analog to Digital Converter. + * + */ + + +#ifndef SAM3_ADC_H +#define SAM3_ADC_H + +/** ADC registers base. */ +#define ADC_BASE 0x400C0000 + +/** + * ADC control register + * \{ + */ +#define ADC_CR_OFF 0x00000000 ///< Control register offeset. +#define ADC_CR (*((reg32_t *)(ADC_BASE + ADC_CR_OFF))) ///< Control register address. +#define ADC_SWRST 0 ///< Software reset. +#define ADC_START 1 ///< Start conversion. +/* \} */ + +/** + * ADC mode register + * \{ + */ +#define ADC_MR_OFF 0x00000004 ///< Mode register offeset. +#define ADC_MR (*((reg32_t *)(ADC_BASE + ADC_MR_OFF))) ///< Mode register address. +#define ADC_TRGEN 0 ///< Trigger enable. + +#define ADC_TRGSEL_TIOA0 0x00000000 ///< TIOA output of the timer counter channel 0. +#define ADC_TRGSEL_TIOA1 0x00000002 ///< TIOA output of the timer counter channel 1. +#define ADC_TRGSEL_TIOA2 0x00000004 ///< TIOA output of the timer counter channel 2. +#define ADC_TRGSEL_PWM0 0x0000000A ///< PWM Event Line 0. +#define ADC_TRGSEL_PWM1 0x0000000C ///< PWM Event Line 1. + +#define ADC_LOWRES 4 ///< Resolution 0: 12-bit, 1: 10-bit. +#define ADC_SLEEP 5 ///< Sleep mode. + + +/** + * Prescaler rate selection. + * ADCClock = MCK / ((ADC_PRESCALER_VALUE + 1) * 2) + */ +#define ADC_PRESCALER_MASK 0x0000FF00 ///< Prescaler rate selection mask. +#define ADC_PRESCALER_SHIFT 8 ///< Prescale rate selection shift. + +/** + * Start up timer. + */ +#define ADC_STARTUP_MASK 0x000F0000 ///< Start up timer mask. +#define ADC_STARTUP_SHIFT 16 ///< Start up timer shift. + +#define ADC_SUT0 0 ///< 0 period of ADCClock. +#define ADC_SUT8 1 ///< 8 period of ADCClock. +#define ADC_SUT16 2 ///< 16 period of ADCClock. +#define ADC_SUT24 3 ///< 24 period of ADCClock. +#define ADC_SUT64 4 ///< 64 period of ADCClock. +#define ADC_SUT80 5 ///< 80 period of ADCClock. +#define ADC_SUT96 6 ///< 96 period of ADCClock. +#define ADC_S... [truncated message content] |
From: Jérémie D. <Ba...@us...> - 2011-03-19 16:22:01
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 6409bfb8555556ae6d525498687b33f1ec8d125f (commit) from 97c23c71ca7612812e3e6e1faaa59b75084b2c68 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6409bfb8555556ae6d525498687b33f1ec8d125f Author: Jérémie Dimino <je...@di...> Date: Sat Mar 19 17:21:11 2011 +0100 [info] add a tool for recording can frames and a tool for replaying them ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index ad461ed..b85b498 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -76,6 +76,20 @@ Executable "krobot-dump" MainIs: krobot_dump.ml BuildDepends: krobot, lwt.syntax +Executable "krobot-record" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_record.ml + BuildDepends: krobot, lwt.syntax + +Executable "krobot-replay" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_replay.ml + BuildDepends: krobot, lwt.syntax + Executable "krobot-plot" Path: src/tools Install: true diff --git a/info/control2011/_tags b/info/control2011/_tags index 91cf530..9c6da6c 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 737f6ffc25aca37ee689df337eca3afe) +# DO NOT EDIT (digest: 404e613a369861087dfd1cb3215a1db4) # Library krobot-interfaces "src/interfaces": include <src/interfaces/*.ml{,i}>: pkg_obus @@ -44,6 +44,12 @@ <src/driver/*.ml{,i}>: pkg_obus <src/driver/*.ml{,i}>: pkg_lwt.unix <src/driver/*.ml{,i}>: pkg_lwt.syntax +# Executable krobot-replay +<src/tools/krobot_replay.{native,byte}>: use_krobot +<src/tools/krobot_replay.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_replay.{native,byte}>: pkg_obus +<src/tools/krobot_replay.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_replay.{native,byte}>: pkg_lwt.syntax # Executable dump-can <examples/dump_can.{native,byte}>: use_krobot-can <examples/dump_can.{native,byte}>: use_krobot @@ -57,6 +63,12 @@ <examples/*.ml{,i}>: pkg_obus <examples/*.ml{,i}>: pkg_lwt.unix <examples/*.ml{,i}>: pkg_lwt.syntax +# Executable krobot-record +<src/tools/krobot_record.{native,byte}>: use_krobot +<src/tools/krobot_record.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_record.{native,byte}>: pkg_obus +<src/tools/krobot_record.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_record.{native,byte}>: pkg_lwt.syntax # Executable krobot-plot <src/tools/krobot_plot.{native,byte}>: use_krobot <src/tools/krobot_plot.{native,byte}>: use_krobot-interfaces diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index aa37ba5..3e81a39 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: c4a37702729314af3884a7f930148eae) *) +(* DO NOT EDIT (digest: c0061e3e8da638912d5008f7a294c616) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5244,6 +5244,33 @@ let setup_t = {exec_custom = false; exec_main_is = "krobot_driver.ml"; }); Executable ({ + cs_name = "krobot-replay"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + {exec_custom = false; exec_main_is = "krobot_replay.ml"; }); + Executable + ({ cs_name = "dump-can"; cs_data = PropList.Data.create (); cs_plugin_data = []; @@ -5271,6 +5298,33 @@ let setup_t = {exec_custom = false; exec_main_is = "dump_can.ml"; }); Executable ({ + cs_name = "krobot-record"; + cs_data = PropList.Data.create (); + cs_plugin_data = []; + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "src/tools"; + bs_compiled_object = Best; + bs_build_depends = + [ + InternalLibrary "krobot"; + FindlibPackage ("lwt.syntax", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])]; + }, + {exec_custom = false; exec_main_is = "krobot_record.ml"; }); + Executable + ({ cs_name = "krobot-plot"; cs_data = PropList.Data.create (); cs_plugin_data = []; diff --git a/info/control2011/src/lib/krobot_can.ml b/info/control2011/src/lib/krobot_can.ml index 02a64f6..b533422 100644 --- a/info/control2011/src/lib/krobot_can.ml +++ b/info/control2011/src/lib/krobot_can.ml @@ -170,7 +170,7 @@ let value_of_frame (timestamp, frame) = | F29bits -> 1l), frame.data) -let frame_of_values (timestamp, identifier, kind, remote, format, data) = +let frame_of_tuple (timestamp, identifier, kind, remote, format, data) = let identifier = Int32.to_int identifier in let kind = match kind with @@ -187,7 +187,7 @@ let frame_of_values (timestamp, identifier, kind, remote, format, data) = (timestamp, frame ~identifier ~kind ~remote ~format ~data) let frame_of_value v = - frame_of_values (C.cast_single typ v) + frame_of_tuple (C.cast_single typ v) (* +-----------------------------------------------------------------+ | Sending/receiving frames | @@ -214,5 +214,5 @@ let recv bus = (E.delay (OBus_signal.connect (OBus_signal.with_context - (OBus_signal.map frame_of_values + (OBus_signal.map frame_of_tuple (OBus_signal.make Krobot_interface_can.Fr_krobot_CAN.s_message proxy))))) diff --git a/info/control2011/src/lib/krobot_can.mli b/info/control2011/src/lib/krobot_can.mli index 717092d..a0f9869 100644 --- a/info/control2011/src/lib/krobot_can.mli +++ b/info/control2011/src/lib/krobot_can.mli @@ -97,6 +97,9 @@ val value_of_frame : float * frame -> OBus_value.V.single val frame_of_value : OBus_value.V.single -> float * frame (** Converts a D-Bus structure into a can frame. *) +val frame_of_tuple : float * int32 * int32 * bool * int32 * string -> float * frame + (** Converts a tuple into a can frame. *) + (** {6 Sending/receiving frames} *) val send : Krobot_bus.t -> (float * frame) -> unit Lwt.t diff --git a/info/control2011/src/tools/krobot_record.ml b/info/control2011/src/tools/krobot_record.ml new file mode 100644 index 0000000..be68c96 --- /dev/null +++ b/info/control2011/src/tools/krobot_record.ml @@ -0,0 +1,31 @@ +(* + * krobot_record.ml + * ---------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* Record CAN frames. *) + +open Lwt +open Lwt_react + +lwt () = + let file = ref "krobot.record" in + Krobot_init.arg "-output" (Arg.Set_string file) "<file> output file"; + lwt bus = Krobot_init.init_program "Record" in + + lwt oc = Lwt_io.open_file ~mode:Lwt_io.output !file in + + (* The proxy for the driver. *) + let driver = OBus_proxy.make (OBus_peer.make (Krobot_bus.to_bus bus) "fr.krobot.Driver") ["fr"; "krobot"; "CAN"] in + + (* Receive frames comming from the driver. *) + lwt ev = OBus_signal.connect (OBus_signal.make Krobot_interface_can.Fr_krobot_CAN.s_message driver) in + + (* Write all frames to the output file. *) + E.keep (E.map_s (fun v -> Lwt_io.write_value oc (Krobot_can.frame_of_tuple v)) ev); + + fst (wait ()) diff --git a/info/control2011/src/tools/krobot_replay.ml b/info/control2011/src/tools/krobot_replay.ml new file mode 100644 index 0000000..ffabded --- /dev/null +++ b/info/control2011/src/tools/krobot_replay.ml @@ -0,0 +1,33 @@ +(* + * krobot_replay.ml + * ---------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* Record CAN frames. *) + +open Lwt +open Lwt_react + +lwt () = + let file = ref "krobot.record" in + Krobot_init.arg "-input" (Arg.Set_string file) "<file> input file"; + lwt bus = Krobot_init.init_program "Record" in + + lwt ic = Lwt_io.open_file ~mode:Lwt_io.input !file in + + try_lwt + (* Read the first frame. *) + lwt timestamp, frame = Lwt_io.read_value ic in + (* Compute the difference of time to add to each timestamp. *) + let delta = Unix.gettimeofday () -. timestamp in + lwt () = Krobot_can.send bus (timestamp +. delta, frame) in + while_lwt true do + lwt timestamp, frame = Lwt_io.read_value ic in + Krobot_can.send bus (timestamp +. delta, frame) + done + with End_of_file -> + Lwt_io.close ic hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-18 22:54:33
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 97c23c71ca7612812e3e6e1faaa59b75084b2c68 (commit) from 2575398f14920cd962c2ed4aae14093114df62ca (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 97c23c71ca7612812e3e6e1faaa59b75084b2c68 Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 23:53:46 2011 +0100 [Controller_Motor_STM32] Try to transmit floats in can_monitor ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c index a7369a2..f853175 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c @@ -18,11 +18,21 @@ typedef struct { uint16_t padding __attribute__((__packed__)); } encoder_msg_t; +typedef struct { + float position __attribute__((__packed__)); + float speed __attribute__((__packed__)); +} motor_msg_t; + typedef union { - encoder_msg_t data_f; + encoder_msg_t data; uint32_t data32[2]; } encoder_can_msg_t; +typedef struct { + motor_msg_t data; + uint32_t data32[2]; +} motor_can_msg_t; + // Process for communication static void NORETURN canMonitor_process(void); @@ -44,13 +54,13 @@ void canMonitorInit(void) { } static void NORETURN canMonitor_process(void) { - encoder_can_msg_t msg; + encoder_can_msg_t msg_enc; + motor_can_msg_t msg_mot; can_tx_frame txm; Timer timer_can; - uint8_t ind = 0; // Initialize constant parameters of TX frame - txm.dlc = 6; + txm.dlc = 8; txm.rtr = 0; txm.ide = 1; txm.sid = 0; @@ -61,28 +71,35 @@ static void NORETURN canMonitor_process(void) { timer_add(&timer_can); - // Sending ENCODER1 and ENCODER2 data - msg.data_f.encoder1_pos = getEncoderPosition(ENCODER1); - msg.data_f.encoder2_pos = getEncoderPosition(ENCODER2); - msg.data_f.encoder1_dir = getEncoderDirection(ENCODER1); - msg.data_f.encoder2_dir = getEncoderDirection(ENCODER2); + // Sending ENCODER3 and ENCODER4 data + msg_enc.data.encoder1_pos = getEncoderPosition(ENCODER3); + msg_enc.data.encoder2_pos = getEncoderPosition(ENCODER4); + msg_enc.data.encoder1_dir = getEncoderDirection(ENCODER3); + msg_enc.data.encoder2_dir = getEncoderDirection(ENCODER4); - txm.data32[0] = msg.data32[0]; - txm.data32[1] = msg.data32[1]; + txm.data32[0] = msg_enc.data32[0]; + txm.data32[1] = msg_enc.data32[1]; txm.eid = 100; can_transmit(CAND1, &txm, ms_to_ticks(10)); - // Sending ENCODER3 and ENCODER4 data - msg.data_f.encoder1_pos = getEncoderPosition(ENCODER3); - msg.data_f.encoder2_pos = getEncoderPosition(ENCODER4); - msg.data_f.encoder1_dir = getEncoderDirection(ENCODER3); - msg.data_f.encoder2_dir = getEncoderDirection(ENCODER4); + // Sending MOTOR3 data + msg_mot.data.position = mc_getPosition(MOTOR3); + msg_mot.data.speed = mc_getSpeed(MOTOR3); - txm.data32[0] = msg.data32[0]; - txm.data32[1] = msg.data32[1]; + txm.data32[0] = msg_mot.data32[0]; + txm.data32[1] = msg_mot.data32[1]; txm.eid = 101; can_transmit(CAND1, &txm, ms_to_ticks(10)); + // Sending MOTOR4 data + msg_mot.data.position = mc_getPosition(MOTOR4); + msg_mot.data.speed = mc_getSpeed(MOTOR4); + + txm.data32[0] = (int32_t)mc_getPosition(MOTOR4);//msg_mot.data32[0]; + txm.data32[1] = (int32_t)mc_getSpeed(MOTOR4);//msg_mot.data32[1]; + txm.eid = 102; + can_transmit(CAND1, &txm, ms_to_ticks(10)); + // Wait for the next transmission timer timer_waitEvent(&timer_can); } diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.h b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.h index 0e5e3a1..9f5be0c 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.h +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.h @@ -14,6 +14,7 @@ #include <drv/timer.h> #include "encoder.h" +#include "motor_controller.h" void canMonitorInit(void); diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c index bd62ea4..d6a4116 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c @@ -82,7 +82,7 @@ static void NORETURN square_process(void) static void NORETURN goto_process(void) { - float inc = 3.6; + float inc = 1.8; float ref = 0; int32_t dt= 5; uint8_t ind = 0; @@ -97,7 +97,7 @@ static void NORETURN goto_process(void) timer_delay(dt); } timer_delay(1000); - mc_delete_controller(MOTOR3); + //mc_delete_controller(MOTOR3); mc_delete_controller(MOTOR4); LED1_OFF(); } hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-18 22:34:49
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 2575398f14920cd962c2ed4aae14093114df62ca (commit) from b628b5a4fac1280c9f818dad667e8ba832222d4d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2575398f14920cd962c2ed4aae14093114df62ca Author: Jérémie Dimino <je...@di...> Date: Fri Mar 18 23:33:56 2011 +0100 [info] closes fds on errors ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/can/can_stubs.c b/info/control2011/src/can/can_stubs.c index 93d63fb..9cdc4b3 100644 --- a/info/control2011/src/can/can_stubs.c +++ b/info/control2011/src/can/can_stubs.c @@ -32,13 +32,19 @@ CAMLprim value ocaml_can_open_can_file_descr(value iface) struct ifreq ifr; strcpy(ifr.ifr_name, String_val(iface)); /* ifr.ifr_ifindex gets filled with that device's index */ - if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) uerror("ioctl", Nothing); + if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { + close(fd); + uerror("ioctl", Nothing); + } /* Select that CAN interface, and bind the socket to it. */ struct sockaddr_can addr; addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; - if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) uerror("bind", Nothing); + if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + close(fd); + uerror("bind", Nothing); + } return Val_int(fd); } diff --git a/info/control2011/src/driver/krobot_driver.ml b/info/control2011/src/driver/krobot_driver.ml index dab0a02..59f3851 100644 --- a/info/control2011/src/driver/krobot_driver.ml +++ b/info/control2011/src/driver/krobot_driver.ml @@ -35,6 +35,7 @@ lwt () = Krobot_can_bus.recv can >>= Krobot_can.send bus done with exn -> + lwt () = Krobot_can_bus.close can in (* Make sure no more messages are sent on the CAN bus. *) set_active false; (* This is just here to keep a reference to [ev]. *) hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-18 22:20:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via b628b5a4fac1280c9f818dad667e8ba832222d4d (commit) from 184d207e0be5f4a681e76f3bd4cea8b59476b414 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b628b5a4fac1280c9f818dad667e8ba832222d4d Author: Jérémie Dimino <je...@di...> Date: Fri Mar 18 23:18:11 2011 +0100 [info] correct implementation of timestamps using ioctls ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/can/can_stubs.c b/info/control2011/src/can/can_stubs.c index c2a1876..93d63fb 100644 --- a/info/control2011/src/can/can_stubs.c +++ b/info/control2011/src/can/can_stubs.c @@ -48,29 +48,19 @@ CAMLprim value ocaml_can_recv(value val_fd) CAMLparam1(val_fd); CAMLlocal3(val_result, val_frame, val); - struct msghdr msg; - struct iovec iov; - uint64_t timestamp; struct can_frame frame; - /* Prepare the IO vector. */ - iov.iov_base = &frame; - iov.iov_len = sizeof(frame); - - /* Prepare the message. */ - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = ×tamp; - msg.msg_controllen = sizeof(timestamp); - /* Receive one frame. */ - int ret = recvmsg(Int_val(val_fd), &msg, 0); - if (ret < 0) uerror("recvmsg", Nothing); + int ret = recv(Int_val(val_fd), &frame, sizeof(frame), 0); + if (ret < 0) uerror("recv", Nothing); /* It is an error if we do not receive exactly one frame. */ if (ret != sizeof(frame)) caml_failwith("recvmsg: invalid size"); + /* Receive the timestamp. */ + struct timeval tv; + if (ioctl(Int_val(val_fd), SIOCGSTAMP, &tv) < 0) uerror("ioctl", Nothing); + /* Build the caml frame. */ val_frame = caml_alloc_tuple(5); Field(val_frame, 0) = Val_int(frame.can_id & CAN_EFF_MASK); @@ -83,24 +73,18 @@ CAMLprim value ocaml_can_recv(value val_fd) /* Build the result containing the timestamp and the frame. */ val_result = caml_alloc_tuple(2); - val = caml_copy_double(timestamp * 1e-9); + val = caml_copy_double(tv.tv_sec + tv.tv_usec * 1e-6); Store_field(val_result, 0, val); Store_field(val_result, 1, val_frame); CAMLreturn(val_result); } -CAMLprim value ocaml_can_send(value val_fd, value val_arg) +CAMLprim value ocaml_can_send(value val_fd, value val_frame) { - struct msghdr msg; - struct iovec iov; - uint64_t timestamp; struct can_frame frame; - timestamp = (uint64_t)(Double_val(Field(val_arg, 0)) * 1e9); - /* Build the can frame. */ - value val_frame = Field(val_arg, 1); frame.can_id = Int_val(Field(val_frame, 0)) | (Int_val(Field(val_frame, 1)) >> 29) | (Int_val(Field(val_frame, 2)) >> 30) | @@ -109,19 +93,8 @@ CAMLprim value ocaml_can_send(value val_fd, value val_arg) frame.can_dlc = caml_string_length(val_data); memcpy(frame.data, String_val(val_data), caml_string_length(val_data)); - /* Prepare the IO vector. */ - iov.iov_base = &frame; - iov.iov_len = sizeof(frame); - - /* Prepare the message. */ - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = ×tamp; - msg.msg_controllen = sizeof(timestamp); - - /* Receive one frame. */ - int ret = sendmsg(Int_val(val_fd), &msg, 0); + /* Send the frame. */ + int ret = send(Int_val(val_fd), &frame, sizeof(frame), 0); if (ret < 0) uerror("sendmsg", Nothing); /* It is an error if we do not sent exactly one frame. */ diff --git a/info/control2011/src/can/krobot_can_bus.ml b/info/control2011/src/can/krobot_can_bus.ml index b3b88db..f0c419f 100644 --- a/info/control2011/src/can/krobot_can_bus.ml +++ b/info/control2011/src/can/krobot_can_bus.ml @@ -46,10 +46,10 @@ let close bus = bus#close +-----------------------------------------------------------------+ *) external can_recv : Unix.file_descr -> float * Krobot_can.frame = "ocaml_can_recv" -external can_send : Unix.file_descr -> float * Krobot_can.frame -> unit = "ocaml_can_send" +external can_send : Unix.file_descr -> Krobot_can.frame -> unit = "ocaml_can_send" let recv bus = Lwt_unix.wrap_syscall Lwt_unix.Read bus#fd (fun () -> can_recv (Lwt_unix.unix_file_descr bus#fd)) -let send bus arg = - Lwt_unix.wrap_syscall Lwt_unix.Write bus#fd (fun () -> can_send (Lwt_unix.unix_file_descr bus#fd) arg) +let send bus (_, frame) = + Lwt_unix.wrap_syscall Lwt_unix.Write bus#fd (fun () -> can_send (Lwt_unix.unix_file_descr bus#fd) frame) hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-18 21:59:14
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 184d207e0be5f4a681e76f3bd4cea8b59476b414 (commit) from f8b4c4bc985a9e6f73229e03035f91f102ad745d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 184d207e0be5f4a681e76f3bd4cea8b59476b414 Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 22:58:18 2011 +0100 [USB_CAN] Typo on packet generation ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c index f345178..bb16436 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c @@ -30,7 +30,7 @@ int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx sprintf(&buffer[i], "%02x", frame->data8[j]); sprintf(&buffer[i], "%04x", timestamp); - i+=2; + i+=4; buffer[i] = '\r'; i++; hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-18 20:34:54
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via f8b4c4bc985a9e6f73229e03035f91f102ad745d (commit) from 79416ac728228e9789e2603a6697289572013d9a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f8b4c4bc985a9e6f73229e03035f91f102ad745d Author: Jérémie Dimino <je...@di...> Date: Fri Mar 18 21:33:59 2011 +0100 [info] implements new can messages ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_can.ml b/info/control2011/src/lib/krobot_can.ml index a9de544..02a64f6 100644 --- a/info/control2011/src/lib/krobot_can.ml +++ b/info/control2011/src/lib/krobot_can.ml @@ -108,6 +108,20 @@ let get_uint32 str ofs = and v3 = Char.code str.[ofs + 3] in v0 lor (v1 lsl 8) lor (v2 lsl 16) lor (v3 lsl 24) +let get_float32 str ofs = + let v0 = Char.code str.[ofs + 0] + and v1 = Char.code str.[ofs + 1] + and v2 = Char.code str.[ofs + 2] + and v3 = Char.code str.[ofs + 3] in + Int32.float_of_bits + (Int32.logor + (Int32.logor + (Int32.of_int v0) + (Int32.shift_left (Int32.of_int v1) 8)) + (Int32.logor + (Int32.shift_left (Int32.of_int v2) 16) + (Int32.shift_left (Int32.of_int v3) 24))) + let put_sint8 str ofs v = str.[ofs] <- Char.unsafe_chr v @@ -127,6 +141,13 @@ let put_sint32 str ofs v = let put_uint32 = put_sint32 +let put_float32 str ofs v = + let v = Int32.bits_of_float v in + str.[ofs + 0] <- Char.unsafe_chr (Int32.to_int v); + str.[ofs + 1] <- Char.unsafe_chr (Int32.to_int (Int32.shift_right v 8)); + str.[ofs + 2] <- Char.unsafe_chr (Int32.to_int (Int32.shift_right v 16)); + str.[ofs + 3] <- Char.unsafe_chr (Int32.to_int (Int32.shift_right v 24)) + (* +-----------------------------------------------------------------+ | D-Bus value conversion | +-----------------------------------------------------------------+ *) diff --git a/info/control2011/src/lib/krobot_can.mli b/info/control2011/src/lib/krobot_can.mli index 1d2d7f0..717092d 100644 --- a/info/control2011/src/lib/krobot_can.mli +++ b/info/control2011/src/lib/krobot_can.mli @@ -76,6 +76,8 @@ val get_uint16 : string -> int -> int val get_sint32 : string -> int -> int val get_uint32 : string -> int -> int +val get_float32 : string -> int -> float + val put_sint8 : string -> int -> int -> unit val put_uint8 : string -> int -> int -> unit @@ -85,6 +87,8 @@ val put_uint16 : string -> int -> int -> unit val put_sint32 : string -> int -> int -> unit val put_uint32 : string -> int -> int -> unit +val put_float32 : string -> int -> float -> unit + (** {6 D-Bus frame conversion} *) val value_of_frame : float * frame -> OBus_value.V.single diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 99defa0..5536716 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -17,57 +17,74 @@ open Lwt_react type direction = Forward | Backward -type encoder_state = { - es_position : int; - es_direction : direction; -} - type t = - | Encoder_state_1_2 of encoder_state * encoder_state - | Encoder_state_3_4 of encoder_state * encoder_state + | Encoder_position_direction_3_4 of int * direction * int * direction + | Encoder_position_speed_3 of float * float + | Encoder_position_speed_4 of float * float | Unknown of frame (* +-----------------------------------------------------------------+ | Message --> string | +-----------------------------------------------------------------+ *) -let string_of_encoder_state es = - sprintf "{ es_position = %d; es_direction = %s }" es.es_position (match es.es_direction with Forward -> "Forward" | Backward -> "Backward") +let string_of_direction = function + | Forward -> "Forward" + | Backward -> "Backward" let to_string = function - | Encoder_state_1_2(c1, c2) -> sprintf "Encoder_state_1_2(%s, %s)" (string_of_encoder_state c1) (string_of_encoder_state c2) - | Encoder_state_3_4(c3, c4) -> sprintf "Encoder_state_3_4(%s, %s)" (string_of_encoder_state c3) (string_of_encoder_state c4) - | Unknown frame -> Krobot_can.string_of_frame frame + | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> + sprintf + "Encoder_position_direction_3_4(%d, %s, %d, %s)" + pos3 (string_of_direction dir3) + pos4 (string_of_direction dir4) + | Encoder_position_speed_3(pos, speed) -> + sprintf + "Encoder_position_speed_3(%f, %f)" + pos speed + | Encoder_position_speed_4(pos, speed) -> + sprintf + "Encoder_position_speed_4(%f, %f)" + pos speed + | Unknown frame -> + Krobot_can.string_of_frame frame (* +-----------------------------------------------------------------+ | Encoding | +-----------------------------------------------------------------+ *) let encode = function - | Encoder_state_1_2(c1, c2) -> + | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> let data = String.create 6 in - put_uint16 data 0 c1.es_position; - put_uint16 data 2 c2.es_position; - put_uint8 data 4 (match c1.es_direction with Forward -> 0 | Backward -> 1); - put_uint8 data 5 (match c2.es_direction with Forward -> 0 | Backward -> 1); + put_uint16 data 0 pos3; + put_uint16 data 2 pos4; + put_uint8 data 4 (match dir3 with Forward -> 0 | Backward -> 1); + put_uint8 data 5 (match dir4 with Forward -> 0 | Backward -> 1); frame ~identifier:100 ~kind:Data ~remote:false ~format:F11bits ~data - | Encoder_state_3_4(c3, c4) -> - let data = String.create 6 in - put_uint16 data 0 c3.es_position; - put_uint16 data 2 c4.es_position; - put_uint8 data 4 (match c3.es_direction with Forward -> 0 | Backward -> 1); - put_uint8 data 5 (match c4.es_direction with Forward -> 0 | Backward -> 1); + | Encoder_position_speed_3(pos, speed) -> + let data = String.create 8 in + put_float32 data 0 pos; + put_float32 data 4 speed; frame ~identifier:101 ~kind:Data ~remote:false ~format:F11bits ~data + | Encoder_position_speed_4(pos, speed) -> + let data = String.create 8 in + put_float32 data 0 pos; + put_float32 data 4 speed; + frame + ~identifier:102 + ~kind:Data + ~remote:false + ~format:F11bits + ~data | Unknown frame -> frame @@ -78,17 +95,19 @@ let encode = function let decode frame = match frame.identifier with | 100 -> - Encoder_state_1_2 - ({ es_position = get_uint16 frame.data 0; - es_direction = if get_uint8 frame.data 4 = 0 then Forward else Backward }, - { es_position = get_uint16 frame.data 2; - es_direction = if get_uint8 frame.data 5 = 0 then Forward else Backward }) + Encoder_position_direction_3_4 + (get_uint16 frame.data 0, + (if get_uint8 frame.data 4 = 0 then Forward else Backward), + get_uint16 frame.data 2, + (if get_uint8 frame.data 5 = 0 then Forward else Backward)) | 101 -> - Encoder_state_3_4 - ({ es_position = get_uint16 frame.data 0; - es_direction = if get_uint8 frame.data 4 = 0 then Forward else Backward }, - { es_position = get_uint16 frame.data 2; - es_direction = if get_uint8 frame.data 5 = 0 then Forward else Backward }) + Encoder_position_speed_3 + (get_float32 frame.data 0, + get_float32 frame.data 4) + | 102 -> + Encoder_position_speed_4 + (get_float32 frame.data 0, + get_float32 frame.data 4) | _ -> Unknown frame diff --git a/info/control2011/src/lib/krobot_message.mli b/info/control2011/src/lib/krobot_message.mli index 399c0c4..eb56dee 100644 --- a/info/control2011/src/lib/krobot_message.mli +++ b/info/control2011/src/lib/krobot_message.mli @@ -12,20 +12,14 @@ type direction = Forward | Backward (** Type of directions. *) -(** Type of state of an encoder. *) -type encoder_state = { - es_position : int; - (** The position of the encoder. *) - es_direction : direction; - (** The direction of the encoder. *) -} - (** Type of messages. *) type t = - | Encoder_state_1_2 of encoder_state * encoder_state - (** State of the encoder 1 and 2. *) - | Encoder_state_3_4 of encoder_state * encoder_state - (** State of the encoder 3 and 4. *) + | Encoder_position_direction_3_4 of int * direction * int * direction + (** The position and direction of encoders 3 and 4. *) + | Encoder_position_speed_3 of float * float + (** The position and speed of encoder 3. *) + | Encoder_position_speed_4 of float * float + (** The position and speed of encoder 4. *) | Unknown of Krobot_can.frame (** An unknown can frame. *) diff --git a/info/control2011/src/tools/krobot_plot.ml b/info/control2011/src/tools/krobot_plot.ml index f99d06e..875c217 100644 --- a/info/control2011/src/tools/krobot_plot.ml +++ b/info/control2011/src/tools/krobot_plot.ml @@ -104,7 +104,7 @@ lwt () = window#show (); (* Create the graph. *) - let graph = { points = Array.init 4 (fun _ -> Queue.create ()); max = 1 } in + let graph = { points = Array.init 2 (fun _ -> Queue.create ()); max = 1 } in (* Draw in a separate thread. *) ignore (Thread.create (fun () -> draw window graph) ()); @@ -113,15 +113,10 @@ lwt () = (E.map (fun (timestamp, msg) -> match msg with - | Encoder_state_1_2(enc1, enc2) -> - graph.max <- max graph.max (max enc1.es_position enc2.es_position); - Queue.push (timestamp, enc1.es_position) graph.points.(0); - Queue.push (timestamp, enc2.es_position) graph.points.(1); - update_graph graph timestamp - | Encoder_state_3_4(enc3, enc4) -> - graph.max <- max graph.max (max enc3.es_position enc4.es_position); - Queue.push (timestamp, enc3.es_position) graph.points.(2); - Queue.push (timestamp, enc4.es_position) graph.points.(3); + | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> + graph.max <- max graph.max (max pos3 pos4); + Queue.push (timestamp, pos3) graph.points.(0); + Queue.push (timestamp, pos4) graph.points.(1); update_graph graph timestamp | _ -> ()) hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-18 20:30:31
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 79416ac728228e9789e2603a6697289572013d9a (commit) via 56e572001b4b5f43faead756f19f644fbe509f75 (commit) from 0d64d8bd6f803f1d1dbc09eb224b352aeb6301b8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 79416ac728228e9789e2603a6697289572013d9a Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 21:06:48 2011 +0100 [USB_CAN] Add timestamp generation when transmitting packets via USB commit 56e572001b4b5f43faead756f19f644fbe509f75 Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 21:05:46 2011 +0100 [USB_CAN] Use toolchain in PATH ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/USB_CAN/Firmware/usb_can/main.c b/elec/boards/USB_CAN/Firmware/usb_can/main.c index a6ac284..01442bf 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/main.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/main.c @@ -143,10 +143,12 @@ static void NORETURN can_receive_process(void) { can_rx_frame frame; int retval; + int32_t timestamp; for (;;) { can_receive(CAND1, &frame, ms_to_ticks(100)); - retval = usb_can_emit(CAND1, &ser, &frame); + timestamp = ticks_to_ms(timer_clock()) % 60000; + retval = usb_can_emit(CAND1, &ser, &frame, (uint16_t)timestamp); kprintf("received something... %d %08lx %08lx\n", frame.ide ? frame.eid:frame.sid, frame.data32[0], frame.data32[1]); } } diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c index 237bcaa..f345178 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.c @@ -5,7 +5,7 @@ int usb_can_execute_command(UNUSED_ARG(can_driver *, candrv), UNUSED_ARG(struct return 0; } -int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx_frame *frame) { +int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx_frame *frame, uint16_t timestamp) { char buffer[32] = ""; int i = 0, j = 0; @@ -29,6 +29,9 @@ int usb_can_emit(UNUSED_ARG(can_driver *, candrv), struct Serial *serial, can_rx for(j = 0; j < frame->dlc; i+=2, j++) sprintf(&buffer[i], "%02x", frame->data8[j]); + sprintf(&buffer[i], "%04x", timestamp); + i+=2; + buffer[i] = '\r'; i++; diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h index efc7d0c..5a8c1ee 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.h @@ -16,6 +16,6 @@ int usb_can_execute_command(can_driver *candrv, struct Serial *serial, char *command); -int usb_can_emit(can_driver *candrv, struct Serial *serial, can_rx_frame *frame); +int usb_can_emit(can_driver *candrv, struct Serial *serial, can_rx_frame *frame, uint16_t timestamp); #endif /* !USB_CAN_H */ diff --git a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.mk b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.mk index a9cc4d2..999adbe 100644 --- a/elec/boards/USB_CAN/Firmware/usb_can/usb_can.mk +++ b/elec/boards/USB_CAN/Firmware/usb_can/usb_can.mk @@ -9,7 +9,7 @@ Firmware_DEBUG = 1 # Our target application TRG += usb_can -usb_can_PREFIX = "/home/nicolasd/opt/arm/bin/arm-none-eabi-" +usb_can_PREFIX = "arm-none-eabi-" usb_can_SUFFIX = "" hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-18 17:28:56
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 0d64d8bd6f803f1d1dbc09eb224b352aeb6301b8 (commit) from 0407514312c9770bd5303f1a20f4afa91237679d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0d64d8bd6f803f1d1dbc09eb224b352aeb6301b8 Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 18:27:02 2011 +0100 [Controller_Motor_STM32] Better demonstration code State space command and state estimator seem to work ! ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c index 370f723..bd62ea4 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c @@ -40,8 +40,8 @@ static void init(void) // Start control of drive motors float k[] = {-68.0325, -1.0205}; float l0[] = {0.0236, 3.9715}; - mc_new_controller(MOTOR3, ENCODER3, 360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); - mc_new_controller(MOTOR4, ENCODER4, 360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); + mc_new_controller(MOTOR3, ENCODER3, -360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); + mc_new_controller(MOTOR4, ENCODER4, -360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); // Blink to say we are ready for (uint8_t i=0; i < 2; i++) { @@ -82,29 +82,24 @@ static void NORETURN square_process(void) static void NORETURN goto_process(void) { - float inc = 100; + float inc = 3.6; float ref = 0; - int32_t dt=1000; + int32_t dt= 5; uint8_t ind = 0; + LED1_ON(); // Make the wheels turn - while(ref < 1500) + while(ref < 7200) { mc_gotoPosition(MOTOR3, ref); mc_gotoPosition(MOTOR4, ref); - //position += speed * ((float)dt)/1000.0; ref = ref + inc; timer_delay(dt); - if(ind) { - LED1_ON(); - ind = 0; - } else { - LED1_OFF(); - ind = 1; - } } + timer_delay(1000); mc_delete_controller(MOTOR3); mc_delete_controller(MOTOR4); + LED1_OFF(); } @@ -115,10 +110,6 @@ int main(void) /* Create a new child process */ proc_new(goto_process, NULL, KERN_MINSTACKSIZE * 8, NULL); - //timer_delay(4000); - //mc_delete_controller(MOTOR3); - //mc_delete_controller(MOTOR4); - /* * The main process is kept to periodically report the stack * utilization of all the processes (1 probe per second). hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-18 12:41:32
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 0407514312c9770bd5303f1a20f4afa91237679d (commit) from d7f900098e0a3b09db5aeed55ba47b71d321a862 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0407514312c9770bd5303f1a20f4afa91237679d Author: Jérémie Dimino <je...@di...> Date: Fri Mar 18 13:40:19 2011 +0100 [info] add timestamp support ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/examples/dump_can.ml b/info/control2011/examples/dump_can.ml index 37305f2..8a39d3c 100644 --- a/info/control2011/examples/dump_can.ml +++ b/info/control2011/examples/dump_can.ml @@ -13,17 +13,18 @@ open Lwt open Krobot_can let rec loop bus = - lwt frame = Krobot_can_bus.recv bus in + lwt timestamp, frame = Krobot_can_bus.recv bus in let buf = Buffer.create 24 in String.iter (fun ch -> Printf.bprintf buf " %02x" (Char.code ch)) frame.data; lwt () = - Lwt_io.printf "can frame received: + Lwt_io.printf "can frame received at %f: id = %d; kind = %s; remote = %B; format = %d bits; data[%d] =%s; " + timestamp frame.identifier (match frame.kind with | Data -> "data" diff --git a/info/control2011/src/can/can_stubs.c b/info/control2011/src/can/can_stubs.c index af4c55e..c2a1876 100644 --- a/info/control2011/src/can/can_stubs.c +++ b/info/control2011/src/can/can_stubs.c @@ -11,6 +11,7 @@ #include <caml/memory.h> #include <caml/alloc.h> #include <caml/unixsupport.h> +#include <caml/fail.h> #include <sys/types.h> #include <sys/socket.h> @@ -19,6 +20,7 @@ #include <linux/can.h> #include <string.h> +#include <stdint.h> CAMLprim value ocaml_can_open_can_file_descr(value iface) { @@ -41,37 +43,89 @@ CAMLprim value ocaml_can_open_can_file_descr(value iface) return Val_int(fd); } -CAMLprim value ocaml_can_get_frame_size() +CAMLprim value ocaml_can_recv(value val_fd) { - return Val_int(sizeof(struct can_frame)); -} + CAMLparam1(val_fd); + CAMLlocal3(val_result, val_frame, val); -/* Cast a caml string into a can frame. */ -#define FRAME(v) ((struct can_frame*)String_val(v)) + struct msghdr msg; + struct iovec iov; + uint64_t timestamp; + struct can_frame frame; -CAMLprim value ocaml_can_forge_frame(value v) -{ - CAMLparam1(v); - CAMLlocal2(result, data); - result = caml_alloc_string(sizeof(struct can_frame)); - FRAME(result)->can_id = Int_val(Field(v, 0)) | (Int_val(Field(v, 1)) >> 29) | (Int_val(Field(v, 2)) >> 30) | (Int_val(Field(v, 3)) >> 31); - data = Field(v, 4); - FRAME(result)->can_dlc = caml_string_length(data); - memcpy(FRAME(result)->data, String_val(data), caml_string_length(data)); - CAMLreturn(result); + /* Prepare the IO vector. */ + iov.iov_base = &frame; + iov.iov_len = sizeof(frame); + + /* Prepare the message. */ + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = ×tamp; + msg.msg_controllen = sizeof(timestamp); + + /* Receive one frame. */ + int ret = recvmsg(Int_val(val_fd), &msg, 0); + if (ret < 0) uerror("recvmsg", Nothing); + + /* It is an error if we do not receive exactly one frame. */ + if (ret != sizeof(frame)) caml_failwith("recvmsg: invalid size"); + + /* Build the caml frame. */ + val_frame = caml_alloc_tuple(5); + Field(val_frame, 0) = Val_int(frame.can_id & CAN_EFF_MASK); + Field(val_frame, 1) = Val_int((frame.can_id << 29) & 1); + Field(val_frame, 2) = Val_int((frame.can_id << 30) & 1); + Field(val_frame, 3) = Val_int((frame.can_id << 31) & 1); + val = caml_alloc_string(frame.can_dlc); + memcpy(String_val(val), frame.data, frame.can_dlc); + Field(val_frame, 4) = val; + + /* Build the result containing the timestamp and the frame. */ + val_result = caml_alloc_tuple(2); + val = caml_copy_double(timestamp * 1e-9); + Store_field(val_result, 0, val); + Store_field(val_result, 1, val_frame); + + CAMLreturn(val_result); } -CAMLprim value ocaml_can_parse_frame(value v) +CAMLprim value ocaml_can_send(value val_fd, value val_arg) { - CAMLparam1(v); - CAMLlocal2(result, data); - result = caml_alloc_tuple(5); - Field(result, 0) = Val_int(FRAME(v)->can_id & CAN_EFF_MASK); - Field(result, 1) = Val_int((FRAME(v)->can_id << 29) & 1); - Field(result, 2) = Val_int((FRAME(v)->can_id << 30) & 1); - Field(result, 3) = Val_int((FRAME(v)->can_id << 31) & 1); - data = caml_alloc_string(FRAME(v)->can_dlc); - memcpy(String_val(data), FRAME(v)->data, FRAME(v)->can_dlc); - Field(result, 4) = data; - CAMLreturn(result); + struct msghdr msg; + struct iovec iov; + uint64_t timestamp; + struct can_frame frame; + + timestamp = (uint64_t)(Double_val(Field(val_arg, 0)) * 1e9); + + /* Build the can frame. */ + value val_frame = Field(val_arg, 1); + frame.can_id = Int_val(Field(val_frame, 0)) | + (Int_val(Field(val_frame, 1)) >> 29) | + (Int_val(Field(val_frame, 2)) >> 30) | + (Int_val(Field(val_frame, 3)) >> 31); + value val_data = Field(val_frame, 4); + frame.can_dlc = caml_string_length(val_data); + memcpy(frame.data, String_val(val_data), caml_string_length(val_data)); + + /* Prepare the IO vector. */ + iov.iov_base = &frame; + iov.iov_len = sizeof(frame); + + /* Prepare the message. */ + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = ×tamp; + msg.msg_controllen = sizeof(timestamp); + + /* Receive one frame. */ + int ret = sendmsg(Int_val(val_fd), &msg, 0); + if (ret < 0) uerror("sendmsg", Nothing); + + /* It is an error if we do not sent exactly one frame. */ + if (ret != sizeof(frame)) caml_failwith("sendmsg: invalid size"); + + return Val_unit; } diff --git a/info/control2011/src/can/krobot_can_bus.ml b/info/control2011/src/can/krobot_can_bus.ml index 688fa3a..b3b88db 100644 --- a/info/control2011/src/can/krobot_can_bus.ml +++ b/info/control2011/src/can/krobot_can_bus.ml @@ -15,22 +15,15 @@ open Lwt exception Closed -class t fd = - let ic = Lwt_io.make ~mode:Lwt_io.input (Lwt_bytes.read fd) - and oc = Lwt_io.make ~mode:Lwt_io.output (Lwt_bytes.write fd) in -object +class t fd = object val mutable up = true - method ic = - if up then ic else raise Closed - - method oc = - if up then oc else raise Closed + method fd = + if up then fd else raise Closed method close = if up then begin up <- false; - lwt () = Lwt_io.close ic and () = Lwt_io.close oc in Lwt_unix.close fd end else return () @@ -52,16 +45,11 @@ let close bus = bus#close | Sending/receiving frames | +-----------------------------------------------------------------+ *) -external forge_frame : Krobot_can.frame -> string = "ocaml_can_forge_frame" -external parse_frame : string -> Krobot_can.frame = "ocaml_can_parse_frame" -external get_frame_size : unit -> int = "ocaml_can_get_frame_size" "noalloc" - -let frame_size = get_frame_size () - -let send bus frame = - Lwt_io.write bus#oc (forge_frame frame) +external can_recv : Unix.file_descr -> float * Krobot_can.frame = "ocaml_can_recv" +external can_send : Unix.file_descr -> float * Krobot_can.frame -> unit = "ocaml_can_send" let recv bus = - let buffer = String.create frame_size in - lwt () = Lwt_io.read_into_exactly bus#ic buffer 0 frame_size in - return (parse_frame buffer) + Lwt_unix.wrap_syscall Lwt_unix.Read bus#fd (fun () -> can_recv (Lwt_unix.unix_file_descr bus#fd)) + +let send bus arg = + Lwt_unix.wrap_syscall Lwt_unix.Write bus#fd (fun () -> can_send (Lwt_unix.unix_file_descr bus#fd) arg) diff --git a/info/control2011/src/can/krobot_can_bus.mli b/info/control2011/src/can/krobot_can_bus.mli index c27199b..d90c68a 100644 --- a/info/control2011/src/can/krobot_can_bus.mli +++ b/info/control2011/src/can/krobot_can_bus.mli @@ -22,8 +22,8 @@ val close : t -> unit Lwt.t exception Closed (** Exception raised when trying to use a closed bus. *) -val send : t -> Krobot_can.frame -> unit Lwt.t - (** [send bus frame] sends [frame] over [bus]. *) +val send : t -> (float * Krobot_can.frame) -> unit Lwt.t + (** [send bus (timestamp, frame)] sends [frame] over [bus]. *) -val recv : t -> Krobot_can.frame Lwt.t +val recv : t -> (float * Krobot_can.frame) Lwt.t (** [recv bus] waits and reads one frame from the given bus. *) diff --git a/info/control2011/src/interfaces/krobot_interface_can.obus b/info/control2011/src/interfaces/krobot_interface_can.obus index c12738e..842d90c 100644 --- a/info/control2011/src/interfaces/krobot_interface_can.obus +++ b/info/control2011/src/interfaces/krobot_interface_can.obus @@ -17,6 +17,6 @@ interface fr.krobot.CAN { socket *) signal message : ( - frame : (uint32 * uint32 * boolean * uint32 * byte array) + frame : (double * uint32 * uint32 * boolean * uint32 * byte array) ) } diff --git a/info/control2011/src/lib/krobot_can.ml b/info/control2011/src/lib/krobot_can.ml index 5565804..a9de544 100644 --- a/info/control2011/src/lib/krobot_can.ml +++ b/info/control2011/src/lib/krobot_can.ml @@ -133,12 +133,13 @@ let put_uint32 = put_sint32 open OBus_value -let typ = C.structure (C.seq5 C.basic_uint32 C.basic_uint32 C.basic_boolean C.basic_uint32 C.byte_array) +let typ = C.structure (C.seq6 C.basic_double C.basic_uint32 C.basic_uint32 C.basic_boolean C.basic_uint32 C.byte_array) -let value_of_frame frame = +let value_of_frame (timestamp, frame) = C.make_single typ - (Int32.of_int frame.identifier, + (timestamp, + Int32.of_int frame.identifier, (match frame.kind with | Data -> 0l | Error -> 1l), @@ -148,7 +149,7 @@ let value_of_frame frame = | F29bits -> 1l), frame.data) -let frame_of_values (identifier, kind, remote, format, data) = +let frame_of_values (timestamp, identifier, kind, remote, format, data) = let identifier = Int32.to_int identifier in let kind = match kind with @@ -162,7 +163,7 @@ let frame_of_values (identifier, kind, remote, format, data) = | 1l -> F29bits | n -> Printf.ksprintf failwith "Krobot_can.frame_of_value: invalid frame format (%ld)" n in - frame ~identifier ~kind ~remote ~format ~data + (timestamp, frame ~identifier ~kind ~remote ~format ~data) let frame_of_value v = frame_of_values (C.cast_single typ v) @@ -171,14 +172,14 @@ let frame_of_value v = | Sending/receiving frames | +-----------------------------------------------------------------+ *) -let send bus frame = +let send bus arg = OBus_connection.send_message (Krobot_bus.to_bus bus) (OBus_message.signal ~path:["fr"; "krobot"; "CAN"] ~interface:"fr.krobot.CAN" ~member:"message" - [value_of_frame frame]) + [value_of_frame arg]) let recv bus = let proxy = OBus_proxy.make (OBus_peer.anonymous (Krobot_bus.to_bus bus)) ["fr"; "krobot"; "CAN"] in diff --git a/info/control2011/src/lib/krobot_can.mli b/info/control2011/src/lib/krobot_can.mli index 3e26ec5..1d2d7f0 100644 --- a/info/control2011/src/lib/krobot_can.mli +++ b/info/control2011/src/lib/krobot_can.mli @@ -87,17 +87,18 @@ val put_uint32 : string -> int -> int -> unit (** {6 D-Bus frame conversion} *) -val value_of_frame : frame -> OBus_value.V.single +val value_of_frame : float * frame -> OBus_value.V.single (** Converts a can frame into a D-Bus structure. *) -val frame_of_value : OBus_value.V.single -> frame +val frame_of_value : OBus_value.V.single -> float * frame (** Converts a D-Bus structure into a can frame. *) (** {6 Sending/receiving frames} *) -val send : Krobot_bus.t -> frame -> unit Lwt.t - (** [send bus frame] sends the given frame over D-Bus. *) +val send : Krobot_bus.t -> (float * frame) -> unit Lwt.t + (** [send bus (timestamp, frame)] sends the given frame over + D-Bus. *) -val recv : Krobot_bus.t -> frame React.event +val recv : Krobot_bus.t -> (float * frame) React.event (** [recv bus] returns is the event which occurs whan a CAN frame is received. *) diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 4e40cc9..99defa0 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -96,5 +96,5 @@ let decode frame = | Sending/receiving messages | +-----------------------------------------------------------------+ *) -let send bus msg = Krobot_can.send bus (encode msg) -let recv bus = E.map decode (Krobot_can.recv bus) +let send bus (timestamp, msg) = Krobot_can.send bus (timestamp, encode msg) +let recv bus = E.map (fun (timestamp, frame) -> (timestamp, decode frame)) (Krobot_can.recv bus) diff --git a/info/control2011/src/lib/krobot_message.mli b/info/control2011/src/lib/krobot_message.mli index c8f5c63..399c0c4 100644 --- a/info/control2011/src/lib/krobot_message.mli +++ b/info/control2011/src/lib/krobot_message.mli @@ -38,8 +38,9 @@ val encode : t -> Krobot_can.frame val decode : Krobot_can.frame -> t (** Decode the given CAN frame into a message. *) -val send : Krobot_bus.t -> t -> unit Lwt.t - (** [send bus message] sends the given message over D-Bus. *) +val send : Krobot_bus.t -> (float * t) -> unit Lwt.t + (** [send bus (timestamp, message)] sends the given message over + D-Bus. *) -val recv : Krobot_bus.t -> t React.event +val recv : Krobot_bus.t -> (float * t) React.event (** [recv bus] is the event which receive messages. *) diff --git a/info/control2011/src/tools/krobot_dump.ml b/info/control2011/src/tools/krobot_dump.ml index cb58243..bf12e32 100644 --- a/info/control2011/src/tools/krobot_dump.ml +++ b/info/control2011/src/tools/krobot_dump.ml @@ -17,8 +17,8 @@ lwt () = E.keep (E.map_s - (fun msg -> - Lwt_io.printl (Krobot_message.to_string msg)) + (fun (timestamp, msg) -> + Lwt_io.printlf "%f, %s" timestamp (Krobot_message.to_string msg)) (Krobot_message.recv bus)); fst (wait ()) diff --git a/info/control2011/src/tools/krobot_plot.ml b/info/control2011/src/tools/krobot_plot.ml index 393377f..f99d06e 100644 --- a/info/control2011/src/tools/krobot_plot.ml +++ b/info/control2011/src/tools/krobot_plot.ml @@ -111,21 +111,20 @@ lwt () = E.keep (E.map - (function - | Encoder_state_1_2(enc1, enc2) -> - let time = Unix.gettimeofday () in - graph.max <- max graph.max (max enc1.es_position enc2.es_position); - Queue.push (time, enc1.es_position) graph.points.(0); - Queue.push (time, enc2.es_position) graph.points.(1); - update_graph graph time - | Encoder_state_3_4(enc3, enc4) -> - let time = Unix.gettimeofday () in - graph.max <- max graph.max (max enc3.es_position enc4.es_position); - Queue.push (time, enc3.es_position) graph.points.(2); - Queue.push (time, enc4.es_position) graph.points.(3); - update_graph graph time - | _ -> - ()) + (fun (timestamp, msg) -> + match msg with + | Encoder_state_1_2(enc1, enc2) -> + graph.max <- max graph.max (max enc1.es_position enc2.es_position); + Queue.push (timestamp, enc1.es_position) graph.points.(0); + Queue.push (timestamp, enc2.es_position) graph.points.(1); + update_graph graph timestamp + | Encoder_state_3_4(enc3, enc4) -> + graph.max <- max graph.max (max enc3.es_position enc4.es_position); + Queue.push (timestamp, enc3.es_position) graph.points.(2); + Queue.push (timestamp, enc4.es_position) graph.points.(3); + update_graph graph timestamp + | _ -> + ()) (Krobot_message.recv bus)); waiter hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2011-03-18 01:23:17
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via d7f900098e0a3b09db5aeed55ba47b71d321a862 (commit) from e3df2a4bc33737f4e785502892d2d2015c795122 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d7f900098e0a3b09db5aeed55ba47b71d321a862 Author: Xavier Lagorce <Xav...@cr...> Date: Fri Mar 18 02:21:35 2011 +0100 [Controller_Motor_STM32] Some little modifications * Increased kernel stack * Initialize initial reference value when creating controller * new demo program to test motor_controller * Controller and estimators should be correctly set for drive motors ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/cfg/cfg_proc.h b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/cfg/cfg_proc.h index 382e0d4..257cab0 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/cfg/cfg_proc.h +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/cfg/cfg_proc.h @@ -86,7 +86,7 @@ * $WIZ$ type = "int" * $WIZ$ min = 0 */ -#define CONFIG_KERN_HEAP_SIZE 4096L +#define CONFIG_KERN_HEAP_SIZE 8192L /** * Module logging level. diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/controller_motor_stm32.mk b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/controller_motor_stm32.mk index 14a7de9..7d1317b 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/controller_motor_stm32.mk +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/controller_motor_stm32.mk @@ -9,7 +9,7 @@ Firmware_DEBUG = 1 # Our target application TRG += controller_motor_stm32 -controller_motor_stm32_PREFIX = "arm-none-eabi-" +controller_motor_stm32_PREFIX = "/home/lxir/opt/arm/bin/arm-none-eabi-" controller_motor_stm32_SUFFIX = "" @@ -22,14 +22,14 @@ controller_motor_stm32_WIZARD_CSRC = \ bertos/cpu/cortex-m3/drv/can_stm32.c \ bertos/cpu/cortex-m3/hw/switch_ctx_cm3.c \ bertos/mware/event.c \ - bertos/kern/monitor.c \ bertos/cpu/cortex-m3/drv/timer_cm3.c \ bertos/struct/heap.c \ bertos/drv/can.c \ - bertos/mware/formatwr.c \ + bertos/kern/monitor.c \ bertos/drv/timer.c \ bertos/kern/signal.c \ bertos/kern/proc.c \ + bertos/mware/formatwr.c \ bertos/mware/hex.c \ # diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c index 89df632..370f723 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/main.c @@ -37,6 +37,12 @@ static void init(void) // Initialize CAN_MONITOR canMonitorInit(); + // Start control of drive motors + float k[] = {-68.0325, -1.0205}; + float l0[] = {0.0236, 3.9715}; + mc_new_controller(MOTOR3, ENCODER3, 360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); + mc_new_controller(MOTOR4, ENCODER4, 360.0/2000.0/15.0, 0.833, 0.015, 0.005, k, -k[0], l0); + // Blink to say we are ready for (uint8_t i=0; i < 2; i++) { LED1_ON(); @@ -57,46 +63,61 @@ static void NORETURN square_process(void) // Let's roll ! while (1) { - motorSetSpeed(MOTOR3 | MOTOR4, 500); - timer_delay(1000); - motorSetSpeed(MOTOR3, -500); - timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 500); - timer_delay(1000); - motorSetSpeed(MOTOR4, -500); - timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 500); + motorSetSpeed(MOTOR3 | MOTOR4, 1500); timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 1000); + motorSetSpeed(MOTOR3 | MOTOR4, -1500); timer_delay(1000); motorSetSpeed(MOTOR3 | MOTOR4, 1500); timer_delay(1000); - // - disableMotor(MOTOR3 | MOTOR4); - /*motorSetSpeed(MOTOR3 | MOTOR4, 2000); - timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 2500); + motorSetSpeed(MOTOR3 | MOTOR4, -1500); timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 3000); + motorSetSpeed(MOTOR3 | MOTOR4, 1500); timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 3500); + motorSetSpeed(MOTOR3 | MOTOR4, -1500); timer_delay(1000); - motorSetSpeed(MOTOR3 | MOTOR4, 0); - timer_delay(1000);*/ + disableMotor(MOTOR3 | MOTOR4); break; } } +static void NORETURN goto_process(void) +{ + float inc = 100; + float ref = 0; + int32_t dt=1000; + uint8_t ind = 0; + + // Make the wheels turn + while(ref < 1500) + { + mc_gotoPosition(MOTOR3, ref); + mc_gotoPosition(MOTOR4, ref); + //position += speed * ((float)dt)/1000.0; + ref = ref + inc; + timer_delay(dt); + if(ind) { + LED1_ON(); + ind = 0; + } else { + LED1_OFF(); + ind = 1; + } + } + mc_delete_controller(MOTOR3); + mc_delete_controller(MOTOR4); +} + int main(void) { init(); /* Create a new child process */ - proc_new(square_process, NULL, KERN_MINSTACKSIZE * 2, NULL); + proc_new(goto_process, NULL, KERN_MINSTACKSIZE * 8, NULL); - enableMotor(MOTOR3 | MOTOR4); - LED1_ON(); LED2_ON(); + //timer_delay(4000); + //mc_delete_controller(MOTOR3); + //mc_delete_controller(MOTOR4); /* * The main process is kept to periodically report the stack diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/motor_controller.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/motor_controller.c index cd19110..680f3e1 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/motor_controller.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/motor_controller.c @@ -195,6 +195,7 @@ uint8_t mc_new_controller(uint8_t motor, uint8_t encoder, float encoder_gain, fl params->last_estimate[0] = 0; params->last_estimate[1] = 0; params->last_output = params->last_estimate[0]; params->last_encoder_pos = getEncoderPosition(encoder); + params->reference = 0; params->F[0] = 1; params->F[1] = tau*(1-exp(-T/tau)); diff --git a/elec/boards/Controller_Motor_STM32/Firmware/project.bertos b/elec/boards/Controller_Motor_STM32/Firmware/project.bertos index 33b0c75..e2a1b7f 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/project.bertos +++ b/elec/boards/Controller_Motor_STM32/Firmware/project.bertos @@ -29,11 +29,11 @@ p13 (lp14 S'signal' p15 -aS'debug' -p16 aS'kernel' -p17 +p16 aS'monitor' +p17 +aS'debug' p18 aS'timer' p19 hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-17 20:41:19
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via e3df2a4bc33737f4e785502892d2d2015c795122 (commit) from 76c6568221d3133754d2737441d8abeade097416 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit e3df2a4bc33737f4e785502892d2d2015c795122 Author: Jérémie Dimino <je...@di...> Date: Thu Mar 17 21:40:27 2011 +0100 [info] typo ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index bd424fb..4e40cc9 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -36,7 +36,7 @@ let string_of_encoder_state es = let to_string = function | Encoder_state_1_2(c1, c2) -> sprintf "Encoder_state_1_2(%s, %s)" (string_of_encoder_state c1) (string_of_encoder_state c2) - | Encoder_state_3_4(c3, c4) -> sprintf "Encoder_state_1_2(%s, %s)" (string_of_encoder_state c3) (string_of_encoder_state c4) + | Encoder_state_3_4(c3, c4) -> sprintf "Encoder_state_3_4(%s, %s)" (string_of_encoder_state c3) (string_of_encoder_state c4) | Unknown frame -> Krobot_can.string_of_frame frame (* +-----------------------------------------------------------------+ hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-17 17:50:37
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 76c6568221d3133754d2737441d8abeade097416 (commit) from a2b57864d1452b99d01b96efdc7aea7765f3a566 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 76c6568221d3133754d2737441d8abeade097416 Author: Jérémie Dimino <je...@di...> Date: Thu Mar 17 18:49:59 2011 +0100 [info] make the driver to never fail ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/driver/krobot_driver.ml b/info/control2011/src/driver/krobot_driver.ml index fe7af7f..dab0a02 100644 --- a/info/control2011/src/driver/krobot_driver.ml +++ b/info/control2011/src/driver/krobot_driver.ml @@ -19,13 +19,29 @@ let () = Krobot_init.arg "-device" (Arg.Set_string device) "<device> The device lwt () = lwt bus = Krobot_init.init_service "Driver" in - (* Open the CAN bus. *) - lwt can = Krobot_can_bus.open_can !device in - - (* D-Bus --> CAN *) - E.keep (E.map_s (Krobot_can_bus.send can) (Krobot_can.recv bus)); - - (* CAN --> D-Bus *) while_lwt true do - Krobot_can_bus.recv can >>= Krobot_can.send bus + try_lwt + (* Open the CAN bus. *) + lwt can = Krobot_can_bus.open_can !device in + + let active, set_active = S.create true in + + (* D-Bus --> CAN *) + let ev = E.map_s (Krobot_can_bus.send can) (E.when_ active (Krobot_can.recv bus)) in + + try_lwt + (* CAN --> D-Bus *) + while_lwt true do + Krobot_can_bus.recv can >>= Krobot_can.send bus + done + with exn -> + (* Make sure no more messages are sent on the CAN bus. *) + set_active false; + (* This is just here to keep a reference to [ev]. *) + E.stop ev; + raise_lwt exn + with exn -> + lwt () = Lwt_log.error ~exn "failure" in + (* Wait a bit before retrying. *) + Lwt_unix.sleep 0.5 done hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2011-03-17 17:38:14
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via a2b57864d1452b99d01b96efdc7aea7765f3a566 (commit) from 0ef1a91b2e2b76850c49e886509582c29fedca10 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a2b57864d1452b99d01b96efdc7aea7765f3a566 Author: Jérémie Dimino <je...@di...> Date: Thu Mar 17 18:37:48 2011 +0100 [info] use Krobot_init in programs ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_init.ml b/info/control2011/src/lib/krobot_init.ml index 65ddc81..7798d21 100644 --- a/info/control2011/src/lib/krobot_init.ml +++ b/info/control2011/src/lib/krobot_init.ml @@ -27,7 +27,7 @@ let () = None) let program_name = Filename.basename Sys.executable_name -let usage = Printf.sprintf "%s <options>" program_name +let usage = Printf.sprintf "Usage: %s <options>\noptions are:" program_name (* +-----------------------------------------------------------------+ | Command line arguments | diff --git a/info/control2011/src/tools/krobot_dump.ml b/info/control2011/src/tools/krobot_dump.ml index fd0e339..cb58243 100644 --- a/info/control2011/src/tools/krobot_dump.ml +++ b/info/control2011/src/tools/krobot_dump.ml @@ -13,7 +13,7 @@ open Lwt open Lwt_react lwt () = - lwt bus = Krobot_bus.get () in + lwt bus = Krobot_init.init_program "Dump" in E.keep (E.map_s diff --git a/info/control2011/src/tools/krobot_plot.ml b/info/control2011/src/tools/krobot_plot.ml index 26768b2..393377f 100644 --- a/info/control2011/src/tools/krobot_plot.ml +++ b/info/control2011/src/tools/krobot_plot.ml @@ -91,6 +91,8 @@ let draw window graph = +-----------------------------------------------------------------+ *) lwt () = + lwt bus = Krobot_init.init_program "Plot" in + ignore (GMain.init ()); Lwt_glib.install (); @@ -107,8 +109,6 @@ lwt () = (* Draw in a separate thread. *) ignore (Thread.create (fun () -> draw window graph) ()); - lwt bus = Krobot_bus.get () in - E.keep (E.map (function hooks/post-receive -- krobot |