Skip to content
Browse files

Use a read with timeout for draining the device

  • Loading branch information...
1 parent 962581e commit 5aa5a6bc7dc41120c137d96c7b965bccc97b6ae8 @msantos committed Mar 11, 2012
Showing with 5 additions and 30 deletions.
  1. +5 −30 src/stk500.erl
View
35 src/stk500.erl
@@ -40,7 +40,6 @@
version/1,
sync/1,
- read/1, read/2,
hex_file/1, hex_file/2,
chunk/2,
@@ -106,15 +105,13 @@ open(Dev, Opt) ->
reset(FD) ->
- ok = dtrrts(FD, off),
- timer:sleep(50),
- ok = dtrrts(FD, on),
- timer:sleep(50),
+ [ begin dtrrts(FD, Status),
+ timer:sleep(50) end || Status <- [off, on] ],
- [ begin read(FD), sync(FD) end
- || _ <- lists:seq(1,3) ],
+ [ begin serctl:readx(FD, 2, 250),
+ sync(FD) end || _ <- lists:seq(1,3) ],
- read(FD),
+ serctl:readx(FD, 2, 250),
ok.
@@ -167,13 +164,6 @@ sync(FD) ->
cmd(FD, <<?Cmnd_STK_GET_SYNC, ?Sync_CRC_EOP>>).
-% Read up to N bytes
-read(FD) ->
- read(FD, 2).
-read(FD, N) ->
- poll(FD, N, 10).
-
-
hex_file(File) ->
hex_file(intel, File).
@@ -260,21 +250,6 @@ chunk(Bytes, Size, Acc) when Size > 0, Size rem 2 == 0, Size =< 256 ->
bin_to_int(N, Base) ->
list_to_integer(binary_to_list(N), Base).
-
-poll(_FD, _Num, 0) ->
- {error, eagain};
-poll(FD, NumBytes, Retry) ->
- case serctl:read(FD, NumBytes) of
- {error, eagain} ->
- timer:sleep(25),
- poll(FD, NumBytes, Retry-1);
- {ok, Buf} ->
- {ok, Buf};
- Error ->
- Error
- end.
-
-
bool(0) -> off;
bool(1) -> on.

0 comments on commit 5aa5a6b

Please sign in to comment.
Something went wrong with that request. Please try again.