LP-604 Add suitable lowpass filter to feed forward term
[librepilot.git] / flight / libraries / PyMite / lib / ipm.py
blob981ba1edd7fd73b812dc73aba2a85ebf8936f383
1 # This file is Copyright 2007, 2009, 2010 Dean Hall.
3 # This file is part of the Python-on-a-Chip program.
4 # Python-on-a-Chip is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
7 # Python-on-a-Chip is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
11 # is seen in the file COPYING in this directory.
13 ## @file
14 # @copybrief ipm_target
16 ## @package ipm_target
17 # @brief Provides PyMite's interactive interface for the target.
21 # Receives an image over the platform's standard connection.
22 # Returns the image in a string object
24 def _getImg():
25 """__NATIVE__
26 PmReturn_t retval;
27 uint8_t imgType;
28 uint16_t imgSize;
29 uint8_t *pchunk;
30 pPmCodeImgObj_t pimg;
31 uint16_t i;
32 uint8_t b;
34 /* Get the image type */
35 retval = plat_getByte(&imgType);
36 PM_RETURN_IF_ERROR(retval);
38 /* Quit if a code image type was not received */
39 if (imgType != OBJ_TYPE_CIM)
41 PM_RAISE(retval, PM_RET_EX_STOP);
42 return retval;
45 /* Get the image size (little endien) */
46 retval = plat_getByte(&b);
47 PM_RETURN_IF_ERROR(retval);
48 imgSize = b;
49 retval = plat_getByte(&b);
50 PM_RETURN_IF_ERROR(retval);
51 imgSize |= (b << 8);
53 /* Get space for CodeImgObj */
54 retval = heap_getChunk(sizeof(PmCodeImgObj_t) + imgSize, &pchunk);
55 PM_RETURN_IF_ERROR(retval);
56 pimg = (pPmCodeImgObj_t)pchunk;
57 OBJ_SET_TYPE(pimg, OBJ_TYPE_CIO);
59 /* Start the image with the bytes that have already been received */
60 i = 0;
61 pimg->val[i++] = imgType;
62 pimg->val[i++] = imgSize & 0xFF;
63 pimg->val[i++] = (imgSize >> 8) & 0xFF;
65 /* Get the remaining bytes in the image */
66 for(; i < imgSize; i++)
68 retval = plat_getByte(&b);
69 PM_RETURN_IF_ERROR(retval);
71 pimg->val[i] = b;
74 /* Return the image as a code image object on the stack */
75 NATIVE_SET_TOS((pPmObj_t)pimg);
76 return retval;
77 """
78 pass
81 def x04():
82 """__NATIVE__
83 NATIVE_SET_TOS(PM_NONE);
84 return plat_putByte(0x04);
85 """
86 pass
90 # Runs the target device-side interactive session.
92 def ipm(g={}):
93 while 1:
94 # Wait for a code image, make a code object from it
95 # and evaluate the code object.
96 # #180: One-liner turned into 3 so that objects get bound to roots
97 s = _getImg()
98 co = Co(s)
99 rv = eval(co, g)
100 x04()
102 # Execution should never reach here
103 # The while loop (above) probably caught a StopIteration, accidentally
104 assert False
106 # :mode=c: