forked from M-Labs/artiq
1
0
Fork 0

flash_storage comm: use OK/ERROR replies instead of specific FLASH_WRITE_REPLY

This commit is contained in:
Yann Sionneau 2015-05-29 11:10:40 +02:00
parent aa242f7c66
commit 575dfade38
2 changed files with 9 additions and 12 deletions

View File

@ -43,9 +43,8 @@ class _D2HMsgType(Enum):
RPC_REQUEST = 10 RPC_REQUEST = 10
FLASH_READ_REPLY = 11 FLASH_READ_REPLY = 11
FLASH_WRITE_REPLY = 12 FLASH_OK_REPLY = 12
FLASH_OK_REPLY = 13 FLASH_ERROR_REPLY = 13
FLASH_ERROR_REPLY = 14
class UnsupportedDevice(Exception): class UnsupportedDevice(Exception):
@ -148,14 +147,11 @@ class CommGeneric:
self.write(b"\x00") self.write(b"\x00")
self.write(value) self.write(value)
_, ty = self._read_header() _, ty = self._read_header()
if ty != _D2HMsgType.FLASH_WRITE_REPLY: if ty != _D2HMsgType.FLASH_OK_REPLY:
if ty == _D2HMsgType.FLASH_ERROR_REPLY: if ty == _D2HMsgType.FLASH_ERROR_REPLY:
raise IOError("Invalid key: not a null-terminated string") raise IOError("Flash storage is full")
else: else:
raise IOError("Incorrect reply from device: {}".format(ty)) 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): def flash_storage_erase(self):
self._write_header(9, _H2DMsgType.FLASH_ERASE_REQUEST) self._write_header(9, _H2DMsgType.FLASH_ERASE_REQUEST)

View File

@ -112,7 +112,6 @@ enum {
REMOTEMSG_TYPE_RPC_REQUEST, REMOTEMSG_TYPE_RPC_REQUEST,
REMOTEMSG_TYPE_FLASH_READ_REPLY, REMOTEMSG_TYPE_FLASH_READ_REPLY,
REMOTEMSG_TYPE_FLASH_WRITE_REPLY,
REMOTEMSG_TYPE_FLASH_OK_REPLY, REMOTEMSG_TYPE_FLASH_OK_REPLY,
REMOTEMSG_TYPE_FLASH_ERROR_REPLY REMOTEMSG_TYPE_FLASH_ERROR_REPLY
}; };
@ -259,9 +258,11 @@ static int process_input(void)
value = key + key_len; value = key + key_len;
ret = fs_write(key, value, value_len); ret = fs_write(key, value, value_len);
buffer_out[8] = REMOTEMSG_TYPE_FLASH_WRITE_REPLY; if(ret)
buffer_out[9] = ret; buffer_out[8] = REMOTEMSG_TYPE_FLASH_OK_REPLY;
submit_output(10); else
buffer_out[8] = REMOTEMSG_TYPE_FLASH_ERROR_REPLY;
submit_output(9);
break; break;
} }
case REMOTEMSG_TYPE_FLASH_ERASE_REQUEST: { case REMOTEMSG_TYPE_FLASH_ERASE_REQUEST: {