From 575dfade38c70154fa3f4936e5f7e034c03ce294 Mon Sep 17 00:00:00 2001 From: Yann Sionneau Date: Fri, 29 May 2015 11:10:40 +0200 Subject: [PATCH] flash_storage comm: use OK/ERROR replies instead of specific FLASH_WRITE_REPLY --- artiq/coredevice/comm_generic.py | 12 ++++-------- soc/runtime/session.c | 9 +++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/artiq/coredevice/comm_generic.py b/artiq/coredevice/comm_generic.py index 3de7b40e1..a737dfb84 100644 --- a/artiq/coredevice/comm_generic.py +++ b/artiq/coredevice/comm_generic.py @@ -43,9 +43,8 @@ class _D2HMsgType(Enum): RPC_REQUEST = 10 FLASH_READ_REPLY = 11 - FLASH_WRITE_REPLY = 12 - FLASH_OK_REPLY = 13 - FLASH_ERROR_REPLY = 14 + FLASH_OK_REPLY = 12 + FLASH_ERROR_REPLY = 13 class UnsupportedDevice(Exception): @@ -148,14 +147,11 @@ class CommGeneric: self.write(b"\x00") self.write(value) _, ty = self._read_header() - if ty != _D2HMsgType.FLASH_WRITE_REPLY: + if ty != _D2HMsgType.FLASH_OK_REPLY: if ty == _D2HMsgType.FLASH_ERROR_REPLY: - raise IOError("Invalid key: not a null-terminated string") + raise IOError("Flash storage is full") else: raise IOError("Incorrect reply from device: {}".format(ty)) - ret = self.read(1) - if ret != b"\x01": - raise IOError("Flash storage is full") def flash_storage_erase(self): self._write_header(9, _H2DMsgType.FLASH_ERASE_REQUEST) diff --git a/soc/runtime/session.c b/soc/runtime/session.c index 9e9ee2726..1a42bb9ad 100644 --- a/soc/runtime/session.c +++ b/soc/runtime/session.c @@ -112,7 +112,6 @@ enum { REMOTEMSG_TYPE_RPC_REQUEST, REMOTEMSG_TYPE_FLASH_READ_REPLY, - REMOTEMSG_TYPE_FLASH_WRITE_REPLY, REMOTEMSG_TYPE_FLASH_OK_REPLY, REMOTEMSG_TYPE_FLASH_ERROR_REPLY }; @@ -259,9 +258,11 @@ static int process_input(void) value = key + key_len; ret = fs_write(key, value, value_len); - buffer_out[8] = REMOTEMSG_TYPE_FLASH_WRITE_REPLY; - buffer_out[9] = ret; - submit_output(10); + if(ret) + buffer_out[8] = REMOTEMSG_TYPE_FLASH_OK_REPLY; + else + buffer_out[8] = REMOTEMSG_TYPE_FLASH_ERROR_REPLY; + submit_output(9); break; } case REMOTEMSG_TYPE_FLASH_ERASE_REQUEST: {