Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main_nat.c
00001 #undef __FILE_ID__ 00002 #define __FILE_ID__ 0x0A 00003 /** 00004 * PyMite usr native function file 00005 * 00006 * automatically created by pmImgCreator.py 00007 * on Wed Jul 21 11:21:27 2010 00008 * 00009 * DO NOT EDIT THIS FILE. 00010 * ANY CHANGES WILL BE LOST. 00011 * 00012 * @file main_nat.c 00013 */ 00014 00015 #define __IN_LIBNATIVE_C__ 00016 00017 /* From: mbed.py */ 00018 #include "mbed.h" 00019 #include "TextLCD.h" 00020 00021 /* Relocated via patch */ 00022 #include "pm.h" 00023 00024 00025 static DigitalOut led1(LED1); 00026 static DigitalOut led2(LED2); 00027 static DigitalOut led3(LED3); 00028 static DigitalOut led4(LED4); 00029 00030 /* PinName lookup table. Converts pin number to PinName. */ 00031 static PinName const pinNumToName[] = { 00032 NC, NC, NC, NC, NC, p5, p6, p7, p8, p9, 00033 p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, 00034 p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, 00035 p30 00036 }; 00037 00038 /* From: net.py */ 00039 00040 #include "EthernetNetIf.h" 00041 #include "HTTPClient.h" 00042 00043 00044 PmReturn_t 00045 nat_placeholder_func(pPmFrame_t *ppframe) 00046 { 00047 00048 /* 00049 * Use placeholder because an index 00050 * value of zero denotes the stdlib. 00051 * This function should not be called. 00052 */ 00053 PmReturn_t retval; 00054 PM_RAISE(retval, PM_RET_EX_SYS); 00055 return retval; 00056 00057 } 00058 00059 PmReturn_t 00060 nat_01_mbed___init__(pPmFrame_t *ppframe) 00061 { 00062 00063 pPmObj_t pself; 00064 pPmObj_t pn; 00065 pPmObj_t pattrs; 00066 PmReturn_t retval = PM_RET_OK; 00067 AnalogIn *adc; 00068 00069 /* Raise TypeError if wrong number of args */ 00070 if (NATIVE_GET_NUM_ARGS() != 2) 00071 { 00072 PM_RAISE(retval, PM_RET_EX_TYPE); 00073 return retval; 00074 } 00075 pself = NATIVE_GET_LOCAL(0); 00076 00077 /* Raise TypeError if arg is not the right type */ 00078 pn = NATIVE_GET_LOCAL(1); 00079 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00080 { 00081 PM_RAISE(retval, PM_RET_EX_TYPE); 00082 return retval; 00083 } 00084 00085 /* Instantiate the C++ object */ 00086 adc = new AnalogIn(pinNumToName[((pPmInt_t)pn)->val]); 00087 00088 /* Save the pointer to adc as an inaccessible attribute */ 00089 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00090 retval = int_new((uint32_t)adc, &pn); 00091 PM_RETURN_IF_ERROR(retval); 00092 retval = dict_setItem(pattrs, PM_NONE, pn); 00093 PM_RETURN_IF_ERROR(retval); 00094 00095 NATIVE_SET_TOS(PM_NONE); 00096 return retval; 00097 00098 } 00099 00100 PmReturn_t 00101 nat_02_mbed_read_u16(pPmFrame_t *ppframe) 00102 { 00103 00104 pPmObj_t pself; 00105 pPmObj_t pn; 00106 pPmObj_t pattrs; 00107 PmReturn_t retval = PM_RET_OK; 00108 AnalogIn *adc; 00109 int32_t n; 00110 00111 /* If wrong number of args, throw type exception */ 00112 if (NATIVE_GET_NUM_ARGS() != 1) 00113 { 00114 PM_RAISE(retval, PM_RET_EX_TYPE); 00115 return retval; 00116 } 00117 pself = NATIVE_GET_LOCAL(0); 00118 00119 /* Get the the C++ instance */ 00120 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00121 retval = dict_getItem(pattrs, PM_NONE, &pn); 00122 PM_RETURN_IF_ERROR(retval); 00123 adc = (AnalogIn *)((pPmInt_t)pn)->val; 00124 00125 /* Return input value on the stack */ 00126 n = adc->read_u16(); 00127 retval = int_new(n, &pn); 00128 NATIVE_SET_TOS(pn); 00129 00130 return retval; 00131 00132 } 00133 00134 PmReturn_t 00135 nat_03_mbed_read(pPmFrame_t *ppframe) 00136 { 00137 00138 pPmObj_t pself; 00139 pPmObj_t pn; 00140 pPmObj_t pattrs; 00141 PmReturn_t retval = PM_RET_OK; 00142 AnalogIn *adc; 00143 float n; 00144 00145 /* Raise TypeError if wrong number of args */ 00146 if (NATIVE_GET_NUM_ARGS() != 1) 00147 { 00148 PM_RAISE(retval, PM_RET_EX_TYPE); 00149 return retval; 00150 } 00151 pself = NATIVE_GET_LOCAL(0); 00152 00153 /* Get the the C++ instance */ 00154 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00155 retval = dict_getItem(pattrs, PM_NONE, &pn); 00156 PM_RETURN_IF_ERROR(retval); 00157 adc = (AnalogIn *)((pPmInt_t)pn)->val; 00158 00159 /* Return input value on the stack */ 00160 n = adc->read(); 00161 retval = float_new(n, &pn); 00162 NATIVE_SET_TOS(pn); 00163 00164 return retval; 00165 00166 } 00167 00168 PmReturn_t 00169 nat_04_mbed___init__(pPmFrame_t *ppframe) 00170 { 00171 00172 pPmObj_t pself; 00173 pPmObj_t pn; 00174 pPmObj_t pattrs; 00175 PmReturn_t retval = PM_RET_OK; 00176 AnalogOut *dac; 00177 00178 00179 /* Raise TypeError if wrong number of args */ 00180 if (NATIVE_GET_NUM_ARGS() != 2) 00181 { 00182 PM_RAISE(retval, PM_RET_EX_TYPE); 00183 return retval; 00184 } 00185 pself = NATIVE_GET_LOCAL(0); 00186 00187 /* Raise TypeError if arg is not the right type */ 00188 pn = NATIVE_GET_LOCAL(1); 00189 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00190 { 00191 PM_RAISE(retval, PM_RET_EX_TYPE); 00192 return retval; 00193 } 00194 00195 /* Instantiate the object */ 00196 dac = new AnalogOut(pinNumToName[((pPmInt_t)pn)->val]); 00197 00198 /* Save the pointer to adc as an inaccessible attribute */ 00199 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00200 retval = int_new((uint32_t)dac, &pn); 00201 PM_RETURN_IF_ERROR(retval); 00202 retval = dict_setItem(pattrs, PM_NONE, pn); 00203 PM_RETURN_IF_ERROR(retval); 00204 00205 NATIVE_SET_TOS(PM_NONE); 00206 return retval; 00207 00208 } 00209 00210 PmReturn_t 00211 nat_05_mbed_write_u16(pPmFrame_t *ppframe) 00212 { 00213 00214 pPmObj_t pself; 00215 pPmObj_t pn; 00216 pPmObj_t pattrs; 00217 PmReturn_t retval = PM_RET_OK; 00218 AnalogOut *dac; 00219 00220 /* Raise TypeError if wrong number of args */ 00221 if (NATIVE_GET_NUM_ARGS() != 2) 00222 { 00223 PM_RAISE(retval, PM_RET_EX_TYPE); 00224 return retval; 00225 } 00226 pself = NATIVE_GET_LOCAL(0); 00227 00228 /* Raise TypeError if arg is not the right type */ 00229 pn = NATIVE_GET_LOCAL(1); 00230 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00231 { 00232 PM_RAISE(retval, PM_RET_EX_TYPE); 00233 return retval; 00234 } 00235 00236 /* Get the the C++ instance */ 00237 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00238 retval = dict_getItem(pattrs, PM_NONE, &pn); 00239 PM_RETURN_IF_ERROR(retval); 00240 dac = (AnalogOut *)((pPmInt_t)pn)->val; 00241 00242 /* Write value to DAC */ 00243 pn = NATIVE_GET_LOCAL(1); 00244 dac->write_u16(((pPmInt_t)pn)->val); 00245 00246 NATIVE_SET_TOS(PM_NONE); 00247 return retval; 00248 00249 } 00250 00251 PmReturn_t 00252 nat_06_mbed_write(pPmFrame_t *ppframe) 00253 { 00254 00255 pPmObj_t pself; 00256 pPmObj_t pn; 00257 pPmObj_t pattrs; 00258 PmReturn_t retval = PM_RET_OK; 00259 AnalogOut *dac; 00260 float n; 00261 00262 /* Raise TypeError if wrong number of args */ 00263 if (NATIVE_GET_NUM_ARGS() != 2) 00264 { 00265 PM_RAISE(retval, PM_RET_EX_TYPE); 00266 return retval; 00267 } 00268 pself = NATIVE_GET_LOCAL(0); 00269 00270 /* Raise TypeError if arg is not the right type */ 00271 pn = NATIVE_GET_LOCAL(1); 00272 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_FLT) 00273 { 00274 PM_RAISE(retval, PM_RET_EX_TYPE); 00275 return retval; 00276 } 00277 00278 /* Get the the C++ instance */ 00279 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00280 retval = dict_getItem(pattrs, PM_NONE, &pn); 00281 PM_RETURN_IF_ERROR(retval); 00282 dac = (AnalogOut *)((pPmInt_t)pn)->val; 00283 00284 /* Saturate and write value to DAC */ 00285 pn = NATIVE_GET_LOCAL(1); 00286 n = ((pPmFloat_t)pn)->val; 00287 if (n < 0.0) 00288 { 00289 n = 0.0; 00290 } 00291 else if (n > 1.0) 00292 { 00293 n = 1.0; 00294 } 00295 dac->write(n); 00296 00297 NATIVE_SET_TOS(PM_NONE); 00298 return retval; 00299 00300 } 00301 00302 PmReturn_t 00303 nat_07_mbed_read(pPmFrame_t *ppframe) 00304 { 00305 00306 pPmObj_t pself; 00307 pPmObj_t pn; 00308 pPmObj_t pattrs; 00309 PmReturn_t retval = PM_RET_OK; 00310 AnalogOut *dac; 00311 float n; 00312 00313 /* Raise TypeError if wrong number of args */ 00314 if (NATIVE_GET_NUM_ARGS() != 1) 00315 { 00316 PM_RAISE(retval, PM_RET_EX_TYPE); 00317 return retval; 00318 } 00319 pself = NATIVE_GET_LOCAL(0); 00320 00321 /* Get the the C++ instance */ 00322 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00323 retval = dict_getItem(pattrs, PM_NONE, &pn); 00324 PM_RETURN_IF_ERROR(retval); 00325 dac = (AnalogOut *)((pPmInt_t)pn)->val; 00326 00327 /* Return output value on the stack */ 00328 n = dac->read(); 00329 retval = float_new(n, &pn); 00330 NATIVE_SET_TOS(pn); 00331 00332 return retval; 00333 00334 } 00335 00336 PmReturn_t 00337 nat_08_mbed___init__(pPmFrame_t *ppframe) 00338 { 00339 00340 pPmObj_t pself; 00341 pPmObj_t pn; 00342 pPmObj_t pattrs; 00343 PmReturn_t retval = PM_RET_OK; 00344 DigitalIn *din; 00345 00346 /* Raise TypeError if wrong number of args */ 00347 if (NATIVE_GET_NUM_ARGS() != 2) 00348 { 00349 PM_RAISE(retval, PM_RET_EX_TYPE); 00350 return retval; 00351 } 00352 pself = NATIVE_GET_LOCAL(0); 00353 00354 /* Raise TypeError if arg is not the right type */ 00355 pn = NATIVE_GET_LOCAL(1); 00356 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00357 { 00358 PM_RAISE(retval, PM_RET_EX_TYPE); 00359 return retval; 00360 } 00361 00362 /* Instantiate the C++ object */ 00363 din = new DigitalIn(pinNumToName[((pPmInt_t)pn)->val]); 00364 00365 /* Save the pointer to adc as an inaccessible attribute */ 00366 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00367 retval = int_new((uint32_t)din, &pn); 00368 PM_RETURN_IF_ERROR(retval); 00369 retval = dict_setItem(pattrs, PM_NONE, pn); 00370 PM_RETURN_IF_ERROR(retval); 00371 00372 NATIVE_SET_TOS(PM_NONE); 00373 return retval; 00374 00375 } 00376 00377 PmReturn_t 00378 nat_09_mbed_read(pPmFrame_t *ppframe) 00379 { 00380 00381 pPmObj_t pself; 00382 pPmObj_t pn; 00383 pPmObj_t pattrs; 00384 PmReturn_t retval = PM_RET_OK; 00385 DigitalIn *din; 00386 int32_t n; 00387 00388 /* If wrong number of args, throw type exception */ 00389 if (NATIVE_GET_NUM_ARGS() != 1) 00390 { 00391 PM_RAISE(retval, PM_RET_EX_TYPE); 00392 return retval; 00393 } 00394 pself = NATIVE_GET_LOCAL(0); 00395 00396 /* Get the the C++ instance */ 00397 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00398 retval = dict_getItem(pattrs, PM_NONE, &pn); 00399 PM_RETURN_IF_ERROR(retval); 00400 din = (DigitalIn *)((pPmInt_t)pn)->val; 00401 00402 /* Return input value on the stack */ 00403 n = din->read(); 00404 retval = int_new(n, &pn); 00405 NATIVE_SET_TOS(pn); 00406 00407 return retval; 00408 00409 } 00410 00411 PmReturn_t 00412 nat_10_mbed___init__(pPmFrame_t *ppframe) 00413 { 00414 00415 pPmObj_t pself; 00416 pPmObj_t pn; 00417 pPmObj_t pattrs; 00418 PmReturn_t retval = PM_RET_OK; 00419 DigitalOut *dout; 00420 00421 /* Raise TypeError if wrong number of args */ 00422 if (NATIVE_GET_NUM_ARGS() != 2) 00423 { 00424 PM_RAISE(retval, PM_RET_EX_TYPE); 00425 return retval; 00426 } 00427 pself = NATIVE_GET_LOCAL(0); 00428 00429 /* Raise TypeError if arg is not the right type */ 00430 pn = NATIVE_GET_LOCAL(1); 00431 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00432 { 00433 PM_RAISE(retval, PM_RET_EX_TYPE); 00434 return retval; 00435 } 00436 00437 /* Instantiate the C++ object */ 00438 dout = new DigitalOut(pinNumToName[((pPmInt_t)pn)->val]); 00439 00440 /* Save the pointer to adc as an inaccessible attribute */ 00441 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00442 retval = int_new((uint32_t)dout, &pn); 00443 PM_RETURN_IF_ERROR(retval); 00444 retval = dict_setItem(pattrs, PM_NONE, pn); 00445 PM_RETURN_IF_ERROR(retval); 00446 00447 NATIVE_SET_TOS(PM_NONE); 00448 return retval; 00449 00450 } 00451 00452 PmReturn_t 00453 nat_11_mbed_read(pPmFrame_t *ppframe) 00454 { 00455 00456 pPmObj_t pself; 00457 pPmObj_t pn; 00458 pPmObj_t pattrs; 00459 PmReturn_t retval = PM_RET_OK; 00460 DigitalOut *dout; 00461 int32_t n; 00462 00463 /* If wrong number of args, throw type exception */ 00464 if (NATIVE_GET_NUM_ARGS() != 1) 00465 { 00466 PM_RAISE(retval, PM_RET_EX_TYPE); 00467 return retval; 00468 } 00469 pself = NATIVE_GET_LOCAL(0); 00470 00471 /* Get the the C++ instance */ 00472 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00473 retval = dict_getItem(pattrs, PM_NONE, &pn); 00474 PM_RETURN_IF_ERROR(retval); 00475 dout = (DigitalOut *)((pPmInt_t)pn)->val; 00476 00477 /* Return input value on the stack */ 00478 n = dout->read(); 00479 retval = int_new(n, &pn); 00480 NATIVE_SET_TOS(pn); 00481 00482 return retval; 00483 00484 } 00485 00486 PmReturn_t 00487 nat_12_mbed_write(pPmFrame_t *ppframe) 00488 { 00489 00490 pPmObj_t pself; 00491 pPmObj_t pn; 00492 pPmObj_t pattrs; 00493 PmReturn_t retval = PM_RET_OK; 00494 DigitalOut *dout; 00495 00496 /* Raise TypeError if wrong number of args */ 00497 if (NATIVE_GET_NUM_ARGS() != 2) 00498 { 00499 PM_RAISE(retval, PM_RET_EX_TYPE); 00500 return retval; 00501 } 00502 pself = NATIVE_GET_LOCAL(0); 00503 00504 /* Raise TypeError if arg is not the right type */ 00505 pn = NATIVE_GET_LOCAL(1); 00506 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00507 { 00508 PM_RAISE(retval, PM_RET_EX_TYPE); 00509 return retval; 00510 } 00511 00512 /* Get the the C++ instance */ 00513 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00514 retval = dict_getItem(pattrs, PM_NONE, &pn); 00515 PM_RETURN_IF_ERROR(retval); 00516 dout = (DigitalOut *)((pPmInt_t)pn)->val; 00517 00518 /* Write value to DAC */ 00519 pn = NATIVE_GET_LOCAL(1); 00520 dout->write(((pPmInt_t)pn)->val); 00521 00522 NATIVE_SET_TOS(PM_NONE); 00523 return retval; 00524 00525 } 00526 00527 PmReturn_t 00528 nat_13_mbed___init__(pPmFrame_t *ppframe) 00529 { 00530 00531 pPmObj_t pself; 00532 pPmObj_t pn; 00533 pPmObj_t pattrs; 00534 PmReturn_t retval = PM_RET_OK; 00535 PwmOut *pwm; 00536 00537 /* Raise TypeError if wrong number of args */ 00538 if (NATIVE_GET_NUM_ARGS() != 2) 00539 { 00540 PM_RAISE(retval, PM_RET_EX_TYPE); 00541 return retval; 00542 } 00543 pself = NATIVE_GET_LOCAL(0); 00544 00545 /* Raise TypeError if arg is not the right type */ 00546 pn = NATIVE_GET_LOCAL(1); 00547 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00548 { 00549 PM_RAISE(retval, PM_RET_EX_TYPE); 00550 return retval; 00551 } 00552 00553 /* Instantiate the C++ object */ 00554 pwm = new PwmOut(pinNumToName[((pPmInt_t)pn)->val]); 00555 00556 /* Save the pointer to pwm as an inaccessible attribute */ 00557 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00558 retval = int_new((uint32_t)pwm, &pn); 00559 PM_RETURN_IF_ERROR(retval); 00560 retval = dict_setItem(pattrs, PM_NONE, pn); 00561 PM_RETURN_IF_ERROR(retval); 00562 00563 NATIVE_SET_TOS(PM_NONE); 00564 return retval; 00565 00566 } 00567 00568 PmReturn_t 00569 nat_14_mbed_read(pPmFrame_t *ppframe) 00570 { 00571 00572 pPmObj_t pself; 00573 pPmObj_t pn; 00574 pPmObj_t pattrs; 00575 PmReturn_t retval = PM_RET_OK; 00576 DigitalOut *dout; 00577 int32_t n; 00578 00579 /* If wrong number of args, throw type exception */ 00580 if (NATIVE_GET_NUM_ARGS() != 1) 00581 { 00582 PM_RAISE(retval, PM_RET_EX_TYPE); 00583 return retval; 00584 } 00585 pself = NATIVE_GET_LOCAL(0); 00586 00587 /* Get the the C++ instance */ 00588 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00589 retval = dict_getItem(pattrs, PM_NONE, &pn); 00590 PM_RETURN_IF_ERROR(retval); 00591 dout = (DigitalOut *)((pPmInt_t)pn)->val; 00592 00593 /* Return input value on the stack */ 00594 n = dout->read(); 00595 retval = int_new(n, &pn); 00596 NATIVE_SET_TOS(pn); 00597 00598 return retval; 00599 00600 } 00601 00602 PmReturn_t 00603 nat_15_mbed_period(pPmFrame_t *ppframe) 00604 { 00605 00606 pPmObj_t pself; 00607 pPmObj_t pn; 00608 pPmObj_t pattrs; 00609 PmReturn_t retval = PM_RET_OK; 00610 PwmOut *pwm; 00611 00612 /* Raise TypeError if wrong number of args */ 00613 if (NATIVE_GET_NUM_ARGS() != 2) 00614 { 00615 PM_RAISE(retval, PM_RET_EX_TYPE); 00616 return retval; 00617 } 00618 pself = NATIVE_GET_LOCAL(0); 00619 00620 /* Raise TypeError if arg is not the right type */ 00621 pn = NATIVE_GET_LOCAL(1); 00622 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00623 { 00624 PM_RAISE(retval, PM_RET_EX_TYPE); 00625 return retval; 00626 } 00627 00628 /* Get the the C++ instance */ 00629 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00630 retval = dict_getItem(pattrs, PM_NONE, &pn); 00631 PM_RETURN_IF_ERROR(retval); 00632 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00633 00634 /* Write value to DAC */ 00635 pn = NATIVE_GET_LOCAL(1); 00636 pwm->period(((pPmInt_t)pn)->val); 00637 00638 NATIVE_SET_TOS(PM_NONE); 00639 return retval; 00640 00641 } 00642 00643 PmReturn_t 00644 nat_16_mbed_period_ms(pPmFrame_t *ppframe) 00645 { 00646 00647 pPmObj_t pself; 00648 pPmObj_t pn; 00649 pPmObj_t pattrs; 00650 PmReturn_t retval = PM_RET_OK; 00651 PwmOut *pwm; 00652 00653 /* Raise TypeError if wrong number of args */ 00654 if (NATIVE_GET_NUM_ARGS() != 2) 00655 { 00656 PM_RAISE(retval, PM_RET_EX_TYPE); 00657 return retval; 00658 } 00659 pself = NATIVE_GET_LOCAL(0); 00660 00661 /* Raise TypeError if arg is not the right type */ 00662 pn = NATIVE_GET_LOCAL(1); 00663 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00664 { 00665 PM_RAISE(retval, PM_RET_EX_TYPE); 00666 return retval; 00667 } 00668 00669 /* Get the the C++ instance */ 00670 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00671 retval = dict_getItem(pattrs, PM_NONE, &pn); 00672 PM_RETURN_IF_ERROR(retval); 00673 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00674 00675 /* Write value to DAC */ 00676 pn = NATIVE_GET_LOCAL(1); 00677 pwm->period_ms(((pPmInt_t)pn)->val); 00678 00679 NATIVE_SET_TOS(PM_NONE); 00680 return retval; 00681 00682 } 00683 00684 PmReturn_t 00685 nat_17_mbed_period_us(pPmFrame_t *ppframe) 00686 { 00687 00688 pPmObj_t pself; 00689 pPmObj_t pn; 00690 pPmObj_t pattrs; 00691 PmReturn_t retval = PM_RET_OK; 00692 PwmOut *pwm; 00693 00694 /* Raise TypeError if wrong number of args */ 00695 if (NATIVE_GET_NUM_ARGS() != 2) 00696 { 00697 PM_RAISE(retval, PM_RET_EX_TYPE); 00698 return retval; 00699 } 00700 pself = NATIVE_GET_LOCAL(0); 00701 00702 /* Raise TypeError if arg is not the right type */ 00703 pn = NATIVE_GET_LOCAL(1); 00704 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00705 { 00706 PM_RAISE(retval, PM_RET_EX_TYPE); 00707 return retval; 00708 } 00709 00710 /* Get the the C++ instance */ 00711 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00712 retval = dict_getItem(pattrs, PM_NONE, &pn); 00713 PM_RETURN_IF_ERROR(retval); 00714 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00715 00716 /* Write value to DAC */ 00717 pn = NATIVE_GET_LOCAL(1); 00718 pwm->period_us(((pPmInt_t)pn)->val); 00719 00720 NATIVE_SET_TOS(PM_NONE); 00721 return retval; 00722 00723 } 00724 00725 PmReturn_t 00726 nat_18_mbed_pulsewidth(pPmFrame_t *ppframe) 00727 { 00728 00729 pPmObj_t pself; 00730 pPmObj_t pn; 00731 pPmObj_t pattrs; 00732 PmReturn_t retval = PM_RET_OK; 00733 PwmOut *pwm; 00734 00735 /* Raise TypeError if wrong number of args */ 00736 if (NATIVE_GET_NUM_ARGS() != 2) 00737 { 00738 PM_RAISE(retval, PM_RET_EX_TYPE); 00739 return retval; 00740 } 00741 pself = NATIVE_GET_LOCAL(0); 00742 00743 /* Raise TypeError if arg is not the right type */ 00744 pn = NATIVE_GET_LOCAL(1); 00745 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00746 { 00747 PM_RAISE(retval, PM_RET_EX_TYPE); 00748 return retval; 00749 } 00750 00751 /* Get the the C++ instance */ 00752 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00753 retval = dict_getItem(pattrs, PM_NONE, &pn); 00754 PM_RETURN_IF_ERROR(retval); 00755 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00756 00757 /* Write value to DAC */ 00758 pn = NATIVE_GET_LOCAL(1); 00759 pwm->pulsewidth(((pPmInt_t)pn)->val); 00760 00761 NATIVE_SET_TOS(PM_NONE); 00762 return retval; 00763 00764 } 00765 00766 PmReturn_t 00767 nat_19_mbed_puslewidth_ms(pPmFrame_t *ppframe) 00768 { 00769 00770 pPmObj_t pself; 00771 pPmObj_t pn; 00772 pPmObj_t pattrs; 00773 PmReturn_t retval = PM_RET_OK; 00774 PwmOut *pwm; 00775 00776 /* Raise TypeError if wrong number of args */ 00777 if (NATIVE_GET_NUM_ARGS() != 2) 00778 { 00779 PM_RAISE(retval, PM_RET_EX_TYPE); 00780 return retval; 00781 } 00782 pself = NATIVE_GET_LOCAL(0); 00783 00784 /* Raise TypeError if arg is not the right type */ 00785 pn = NATIVE_GET_LOCAL(1); 00786 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00787 { 00788 PM_RAISE(retval, PM_RET_EX_TYPE); 00789 return retval; 00790 } 00791 00792 /* Get the the C++ instance */ 00793 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00794 retval = dict_getItem(pattrs, PM_NONE, &pn); 00795 PM_RETURN_IF_ERROR(retval); 00796 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00797 00798 /* Write value to DAC */ 00799 pn = NATIVE_GET_LOCAL(1); 00800 pwm->pulsewidth_ms(((pPmInt_t)pn)->val); 00801 00802 NATIVE_SET_TOS(PM_NONE); 00803 return retval; 00804 00805 } 00806 00807 PmReturn_t 00808 nat_20_mbed_pulsewidth_us(pPmFrame_t *ppframe) 00809 { 00810 00811 pPmObj_t pself; 00812 pPmObj_t pn; 00813 pPmObj_t pattrs; 00814 PmReturn_t retval = PM_RET_OK; 00815 PwmOut *pwm; 00816 00817 /* Raise TypeError if wrong number of args */ 00818 if (NATIVE_GET_NUM_ARGS() != 2) 00819 { 00820 PM_RAISE(retval, PM_RET_EX_TYPE); 00821 return retval; 00822 } 00823 pself = NATIVE_GET_LOCAL(0); 00824 00825 /* Raise TypeError if arg is not the right type */ 00826 pn = NATIVE_GET_LOCAL(1); 00827 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT) 00828 { 00829 PM_RAISE(retval, PM_RET_EX_TYPE); 00830 return retval; 00831 } 00832 00833 /* Get the the C++ instance */ 00834 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00835 retval = dict_getItem(pattrs, PM_NONE, &pn); 00836 PM_RETURN_IF_ERROR(retval); 00837 pwm = (PwmOut *)((pPmInt_t)pn)->val; 00838 00839 /* Write value to DAC */ 00840 pn = NATIVE_GET_LOCAL(1); 00841 pwm->pulsewidth_us(((pPmInt_t)pn)->val); 00842 00843 NATIVE_SET_TOS(PM_NONE); 00844 return retval; 00845 00846 } 00847 00848 PmReturn_t 00849 nat_21_mbed___init__(pPmFrame_t *ppframe) 00850 { 00851 00852 pPmObj_t pself; 00853 pPmObj_t pn; 00854 pPmObj_t ptx; 00855 pPmObj_t prx; 00856 pPmObj_t pattrs; 00857 PmReturn_t retval = PM_RET_OK; 00858 Serial *ser; 00859 00860 /* Raise TypeError if wrong number of args */ 00861 if (NATIVE_GET_NUM_ARGS() != 3) 00862 { 00863 PM_RAISE(retval, PM_RET_EX_TYPE); 00864 return retval; 00865 } 00866 pself = NATIVE_GET_LOCAL(0); 00867 00868 /* Raise TypeError if arg is not the right type */ 00869 ptx = NATIVE_GET_LOCAL(1); 00870 prx = NATIVE_GET_LOCAL(2); 00871 if ((OBJ_GET_TYPE(ptx) != OBJ_TYPE_INT) 00872 || (OBJ_GET_TYPE(prx) != OBJ_TYPE_INT)) 00873 { 00874 PM_RAISE(retval, PM_RET_EX_TYPE); 00875 return retval; 00876 } 00877 00878 /* Instantiate the C++ object */ 00879 ser = new Serial(pinNumToName[((pPmInt_t)ptx)->val], 00880 pinNumToName[((pPmInt_t)prx)->val]); 00881 00882 /* Save the pointer to ser as an inaccessible attribute */ 00883 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00884 retval = int_new((uint32_t)ser, &pn); 00885 PM_RETURN_IF_ERROR(retval); 00886 retval = dict_setItem(pattrs, PM_NONE, pn); 00887 PM_RETURN_IF_ERROR(retval); 00888 00889 NATIVE_SET_TOS(PM_NONE); 00890 return retval; 00891 00892 } 00893 00894 PmReturn_t 00895 nat_22_mbed_putc(pPmFrame_t *ppframe) 00896 { 00897 00898 pPmObj_t pself; 00899 pPmObj_t pn; 00900 pPmObj_t pattrs; 00901 PmReturn_t retval = PM_RET_OK; 00902 Serial *ser; 00903 00904 /* Raise TypeError if wrong number of args */ 00905 if (NATIVE_GET_NUM_ARGS() != 2) 00906 { 00907 PM_RAISE(retval, PM_RET_EX_TYPE); 00908 return retval; 00909 } 00910 pself = NATIVE_GET_LOCAL(0); 00911 00912 /* Raise TypeError if arg is not the right type */ 00913 pn = NATIVE_GET_LOCAL(1); 00914 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR) 00915 { 00916 PM_RAISE(retval, PM_RET_EX_TYPE); 00917 return retval; 00918 } 00919 00920 /* Get the the C++ instance */ 00921 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00922 retval = dict_getItem(pattrs, PM_NONE, &pn); 00923 PM_RETURN_IF_ERROR(retval); 00924 ser = (Serial *)((pPmInt_t)pn)->val; 00925 00926 /* Write value to DAC */ 00927 pn = NATIVE_GET_LOCAL(1); 00928 ser->putc(((pPmString_t)pn)->val[0]); 00929 00930 NATIVE_SET_TOS(PM_NONE); 00931 return retval; 00932 00933 } 00934 00935 PmReturn_t 00936 nat_23_mbed_puts(pPmFrame_t *ppframe) 00937 { 00938 00939 pPmObj_t pself; 00940 pPmObj_t pn; 00941 pPmObj_t pattrs; 00942 PmReturn_t retval = PM_RET_OK; 00943 Serial *ser; 00944 00945 /* Raise TypeError if wrong number of args */ 00946 if (NATIVE_GET_NUM_ARGS() != 2) 00947 { 00948 PM_RAISE(retval, PM_RET_EX_TYPE); 00949 return retval; 00950 } 00951 pself = NATIVE_GET_LOCAL(0); 00952 00953 /* Raise TypeError if arg is not the right type */ 00954 pn = NATIVE_GET_LOCAL(1); 00955 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR) 00956 { 00957 PM_RAISE(retval, PM_RET_EX_TYPE); 00958 return retval; 00959 } 00960 00961 /* Get the the C++ instance */ 00962 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00963 retval = dict_getItem(pattrs, PM_NONE, &pn); 00964 PM_RETURN_IF_ERROR(retval); 00965 ser = (Serial *)((pPmInt_t)pn)->val; 00966 00967 /* Write value to DAC */ 00968 pn = NATIVE_GET_LOCAL(1); 00969 ser->puts((const char *)((pPmString_t)pn)->val); 00970 00971 NATIVE_SET_TOS(PM_NONE); 00972 return retval; 00973 00974 } 00975 00976 PmReturn_t 00977 nat_24_mbed_getc(pPmFrame_t *ppframe) 00978 { 00979 00980 pPmObj_t pself; 00981 pPmObj_t pn; 00982 pPmObj_t pattrs; 00983 PmReturn_t retval = PM_RET_OK; 00984 Serial *ser; 00985 int32_t n; 00986 00987 /* If wrong number of args, throw type exception */ 00988 if (NATIVE_GET_NUM_ARGS() != 1) 00989 { 00990 PM_RAISE(retval, PM_RET_EX_TYPE); 00991 return retval; 00992 } 00993 pself = NATIVE_GET_LOCAL(0); 00994 00995 /* Get the the C++ instance */ 00996 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 00997 retval = dict_getItem(pattrs, PM_NONE, &pn); 00998 PM_RETURN_IF_ERROR(retval); 00999 ser = (Serial *)((pPmInt_t)pn)->val; 01000 01001 /* Return char (as string) on the stack */ 01002 n = ser->getc(); 01003 retval = string_newFromChar((uint8_t)n, &pn); 01004 NATIVE_SET_TOS(pn); 01005 01006 return retval; 01007 01008 } 01009 01010 PmReturn_t 01011 nat_25_mbed___init__(pPmFrame_t *ppframe) 01012 { 01013 01014 pPmObj_t pself; 01015 pPmObj_t pn; 01016 pPmObj_t pmosi; 01017 pPmObj_t pmiso; 01018 pPmObj_t psclk; 01019 pPmObj_t pattrs; 01020 PmReturn_t retval = PM_RET_OK; 01021 SPI *spi; 01022 01023 /* Raise TypeError if wrong number of args */ 01024 if (NATIVE_GET_NUM_ARGS() != 4) 01025 { 01026 PM_RAISE(retval, PM_RET_EX_TYPE); 01027 return retval; 01028 } 01029 pself = NATIVE_GET_LOCAL(0); 01030 01031 /* Raise TypeError if arg is not the right type */ 01032 pmosi = NATIVE_GET_LOCAL(1); 01033 pmiso = NATIVE_GET_LOCAL(2); 01034 psclk = NATIVE_GET_LOCAL(3); 01035 if ((OBJ_GET_TYPE(pmosi) != OBJ_TYPE_INT) 01036 || (OBJ_GET_TYPE(pmiso) != OBJ_TYPE_INT) 01037 || (OBJ_GET_TYPE(psclk) != OBJ_TYPE_INT)) 01038 { 01039 PM_RAISE(retval, PM_RET_EX_TYPE); 01040 return retval; 01041 } 01042 01043 /* Instantiate the C++ object */ 01044 spi = new SPI(pinNumToName[((pPmInt_t)pmosi)->val], 01045 pinNumToName[((pPmInt_t)pmiso)->val], 01046 pinNumToName[((pPmInt_t)psclk)->val]); 01047 01048 /* Save the pointer to ser as an inaccessible attribute */ 01049 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01050 retval = int_new((uint32_t)spi, &pn); 01051 PM_RETURN_IF_ERROR(retval); 01052 retval = dict_setItem(pattrs, PM_NONE, pn); 01053 PM_RETURN_IF_ERROR(retval); 01054 01055 NATIVE_SET_TOS(PM_NONE); 01056 return retval; 01057 01058 } 01059 01060 PmReturn_t 01061 nat_26_mbed_format(pPmFrame_t *ppframe) 01062 { 01063 01064 pPmObj_t pself; 01065 pPmObj_t pn; 01066 pPmObj_t pbits; 01067 pPmObj_t pmode; 01068 pPmObj_t pattrs; 01069 PmReturn_t retval = PM_RET_OK; 01070 SPI *spi; 01071 01072 /* Raise TypeError if wrong number of args */ 01073 if ((NATIVE_GET_NUM_ARGS() < 2) || (NATIVE_GET_NUM_ARGS() > 3)) 01074 { 01075 PM_RAISE(retval, PM_RET_EX_TYPE); 01076 return retval; 01077 } 01078 pself = NATIVE_GET_LOCAL(0); 01079 01080 /* Raise TypeError if arg is not the right type */ 01081 pbits = NATIVE_GET_LOCAL(1); 01082 if (OBJ_GET_TYPE(pbits) != OBJ_TYPE_INT) 01083 { 01084 PM_RAISE(retval, PM_RET_EX_TYPE); 01085 return retval; 01086 } 01087 01088 /* Get the mode arg if it exists */ 01089 pmode = PM_ZERO; 01090 if (NATIVE_GET_NUM_ARGS() == 3) 01091 { 01092 pmode = NATIVE_GET_LOCAL(3); 01093 } 01094 01095 /* Get the the C++ instance */ 01096 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01097 retval = dict_getItem(pattrs, PM_NONE, &pn); 01098 PM_RETURN_IF_ERROR(retval); 01099 spi = (SPI *)((pPmInt_t)pn)->val; 01100 01101 /* Set format args */ 01102 spi->format(((pPmInt_t)pbits)->val, ((pPmInt_t)pmode)->val); 01103 01104 NATIVE_SET_TOS(PM_NONE); 01105 return retval; 01106 01107 } 01108 01109 PmReturn_t 01110 nat_27_mbed_frequency(pPmFrame_t *ppframe) 01111 { 01112 01113 pPmObj_t pself; 01114 pPmObj_t pn; 01115 pPmObj_t phz; 01116 pPmObj_t pattrs; 01117 PmReturn_t retval = PM_RET_OK; 01118 SPI *spi; 01119 01120 /* Raise TypeError if wrong number of args */ 01121 if (NATIVE_GET_NUM_ARGS() != 2) 01122 { 01123 PM_RAISE(retval, PM_RET_EX_TYPE); 01124 return retval; 01125 } 01126 pself = NATIVE_GET_LOCAL(0); 01127 01128 /* Raise TypeError if arg is not the right type */ 01129 phz = NATIVE_GET_LOCAL(1); 01130 if (OBJ_GET_TYPE(phz) != OBJ_TYPE_INT) 01131 { 01132 PM_RAISE(retval, PM_RET_EX_TYPE); 01133 return retval; 01134 } 01135 01136 /* Get the the C++ instance */ 01137 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01138 retval = dict_getItem(pattrs, PM_NONE, &pn); 01139 PM_RETURN_IF_ERROR(retval); 01140 spi = (SPI *)((pPmInt_t)pn)->val; 01141 01142 /* Set frequency */ 01143 spi->frequency(((pPmInt_t)phz)->val); 01144 01145 NATIVE_SET_TOS(PM_NONE); 01146 return retval; 01147 01148 } 01149 01150 PmReturn_t 01151 nat_28_mbed_write(pPmFrame_t *ppframe) 01152 { 01153 01154 pPmObj_t pself; 01155 pPmObj_t pn; 01156 pPmObj_t pv; 01157 pPmObj_t pattrs; 01158 PmReturn_t retval = PM_RET_OK; 01159 SPI *spi; 01160 int32_t r; 01161 01162 /* Raise TypeError if wrong number of args */ 01163 if (NATIVE_GET_NUM_ARGS() != 2) 01164 { 01165 PM_RAISE(retval, PM_RET_EX_TYPE); 01166 return retval; 01167 } 01168 pself = NATIVE_GET_LOCAL(0); 01169 01170 /* Raise TypeError if arg is not the right type */ 01171 pv = NATIVE_GET_LOCAL(1); 01172 if (OBJ_GET_TYPE(pv) != OBJ_TYPE_INT) 01173 { 01174 PM_RAISE(retval, PM_RET_EX_TYPE); 01175 return retval; 01176 } 01177 01178 /* Get the the C++ instance */ 01179 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01180 retval = dict_getItem(pattrs, PM_NONE, &pn); 01181 PM_RETURN_IF_ERROR(retval); 01182 spi = (SPI *)((pPmInt_t)pn)->val; 01183 01184 /* Write the value and return the response */ 01185 r = spi->write(((pPmInt_t)pv)->val); 01186 retval = int_new(r, &pn); 01187 NATIVE_SET_TOS(pn); 01188 return retval; 01189 01190 } 01191 01192 PmReturn_t 01193 nat_29_mbed___init__(pPmFrame_t *ppframe) 01194 { 01195 01196 pPmObj_t pself; 01197 pPmObj_t pn; 01198 pPmObj_t psda; 01199 pPmObj_t pscl; 01200 pPmObj_t pattrs; 01201 PmReturn_t retval = PM_RET_OK; 01202 I2C *i2c; 01203 01204 /* Raise TypeError if wrong number of args */ 01205 if (NATIVE_GET_NUM_ARGS() != 3) 01206 { 01207 PM_RAISE(retval, PM_RET_EX_TYPE); 01208 return retval; 01209 } 01210 pself = NATIVE_GET_LOCAL(0); 01211 01212 /* Raise TypeError if arg is not the right type */ 01213 psda = NATIVE_GET_LOCAL(1); 01214 pscl = NATIVE_GET_LOCAL(2); 01215 if ((OBJ_GET_TYPE(psda) != OBJ_TYPE_INT) 01216 || (OBJ_GET_TYPE(pscl) != OBJ_TYPE_INT)) 01217 { 01218 PM_RAISE(retval, PM_RET_EX_TYPE); 01219 return retval; 01220 } 01221 01222 /* Instantiate the C++ object */ 01223 i2c = new I2C(pinNumToName[((pPmInt_t)psda)->val], 01224 pinNumToName[((pPmInt_t)pscl)->val]); 01225 01226 /* Save the pointer to ser as an inaccessible attribute */ 01227 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01228 retval = int_new((uint32_t)i2c, &pn); 01229 PM_RETURN_IF_ERROR(retval); 01230 retval = dict_setItem(pattrs, PM_NONE, pn); 01231 PM_RETURN_IF_ERROR(retval); 01232 01233 NATIVE_SET_TOS(PM_NONE); 01234 return retval; 01235 01236 } 01237 01238 PmReturn_t 01239 nat_30_mbed_frequency(pPmFrame_t *ppframe) 01240 { 01241 01242 pPmObj_t pself; 01243 pPmObj_t pn; 01244 pPmObj_t phz; 01245 pPmObj_t pattrs; 01246 PmReturn_t retval = PM_RET_OK; 01247 I2C *i2c; 01248 01249 /* Raise TypeError if wrong number of args */ 01250 if (NATIVE_GET_NUM_ARGS() != 2) 01251 { 01252 PM_RAISE(retval, PM_RET_EX_TYPE); 01253 return retval; 01254 } 01255 pself = NATIVE_GET_LOCAL(0); 01256 01257 /* Raise TypeError if arg is not the right type */ 01258 phz = NATIVE_GET_LOCAL(1); 01259 if (OBJ_GET_TYPE(phz) != OBJ_TYPE_INT) 01260 { 01261 PM_RAISE(retval, PM_RET_EX_TYPE); 01262 return retval; 01263 } 01264 01265 /* Get the the C++ instance */ 01266 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01267 retval = dict_getItem(pattrs, PM_NONE, &pn); 01268 PM_RETURN_IF_ERROR(retval); 01269 i2c = (I2C *)((pPmInt_t)pn)->val; 01270 01271 /* Set frequency */ 01272 i2c->frequency(((pPmInt_t)phz)->val); 01273 01274 NATIVE_SET_TOS(PM_NONE); 01275 return retval; 01276 01277 } 01278 01279 PmReturn_t 01280 nat_31_mbed_read(pPmFrame_t *ppframe) 01281 { 01282 01283 pPmObj_t pself; 01284 pPmObj_t pn; 01285 pPmObj_t paddr; 01286 pPmObj_t pdata; 01287 pPmObj_t plen; 01288 pPmObj_t pattrs; 01289 PmReturn_t retval = PM_RET_OK; 01290 I2C *i2c; 01291 01292 /* Raise TypeError if wrong number of args */ 01293 if (NATIVE_GET_NUM_ARGS() != 4) 01294 { 01295 PM_RAISE(retval, PM_RET_EX_TYPE); 01296 return retval; 01297 } 01298 pself = NATIVE_GET_LOCAL(0); 01299 01300 /* Raise TypeError if arg is not the right type */ 01301 paddr = NATIVE_GET_LOCAL(1); 01302 pdata = NATIVE_GET_LOCAL(2); 01303 plen = NATIVE_GET_LOCAL(3); 01304 if ((OBJ_GET_TYPE(paddr) != OBJ_TYPE_INT) 01305 || (OBJ_GET_TYPE(pdata) != OBJ_TYPE_STR) 01306 || (OBJ_GET_TYPE(plen) != OBJ_TYPE_INT)) 01307 { 01308 PM_RAISE(retval, PM_RET_EX_TYPE); 01309 return retval; 01310 } 01311 01312 /* Get the the C++ instance */ 01313 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01314 retval = dict_getItem(pattrs, PM_NONE, &pn); 01315 PM_RETURN_IF_ERROR(retval); 01316 i2c = (I2C *)((pPmInt_t)pn)->val; 01317 01318 /* Read the bytes into the string */ 01319 /* WARNING: Changing the bytes of a string object is BAD. */ 01320 i2c->read(((pPmInt_t)paddr)->val, 01321 (char *)((pPmString_t)pdata)->val, 01322 ((pPmInt_t)plen)->val); 01323 NATIVE_SET_TOS(PM_NONE); 01324 return retval; 01325 01326 } 01327 01328 PmReturn_t 01329 nat_32_mbed_write(pPmFrame_t *ppframe) 01330 { 01331 01332 pPmObj_t pself; 01333 pPmObj_t pn; 01334 pPmObj_t paddr; 01335 pPmObj_t pdata; 01336 pPmObj_t plen; 01337 pPmObj_t pattrs; 01338 PmReturn_t retval = PM_RET_OK; 01339 I2C *i2c; 01340 01341 /* Raise TypeError if wrong number of args */ 01342 if (NATIVE_GET_NUM_ARGS() != 4) 01343 { 01344 PM_RAISE(retval, PM_RET_EX_TYPE); 01345 return retval; 01346 } 01347 pself = NATIVE_GET_LOCAL(0); 01348 01349 /* Raise TypeError if arg is not the right type */ 01350 paddr = NATIVE_GET_LOCAL(1); 01351 pdata = NATIVE_GET_LOCAL(2); 01352 plen = NATIVE_GET_LOCAL(3); 01353 if ((OBJ_GET_TYPE(paddr) != OBJ_TYPE_INT) 01354 || (OBJ_GET_TYPE(pdata) != OBJ_TYPE_STR) 01355 || (OBJ_GET_TYPE(plen) != OBJ_TYPE_INT)) 01356 { 01357 PM_RAISE(retval, PM_RET_EX_TYPE); 01358 return retval; 01359 } 01360 01361 /* Get the the C++ instance */ 01362 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01363 retval = dict_getItem(pattrs, PM_NONE, &pn); 01364 PM_RETURN_IF_ERROR(retval); 01365 i2c = (I2C *)((pPmInt_t)pn)->val; 01366 01367 /* Write the value and return the response */ 01368 i2c->write(((pPmInt_t)paddr)->val, 01369 (char *)((pPmString_t)pdata)->val, 01370 ((pPmInt_t)plen)->val); 01371 NATIVE_SET_TOS(PM_NONE); 01372 return retval; 01373 01374 } 01375 01376 PmReturn_t 01377 nat_33_mbed___init__(pPmFrame_t *ppframe) 01378 { 01379 01380 pPmObj_t pself; 01381 pPmObj_t pn; 01382 pPmObj_t pattrs; 01383 PmReturn_t retval = PM_RET_OK; 01384 TextLCD *lcd; 01385 01386 /* Raise TypeError if wrong number of args */ 01387 if (NATIVE_GET_NUM_ARGS() != 1) 01388 { 01389 PM_RAISE(retval, PM_RET_EX_TYPE); 01390 return retval; 01391 } 01392 pself = NATIVE_GET_LOCAL(0); 01393 01394 /* Instantiate the C++ object */ 01395 lcd = new TextLCD(pinNumToName[24], 01396 pinNumToName[25], 01397 pinNumToName[26], 01398 pinNumToName[27], 01399 pinNumToName[28], 01400 pinNumToName[29], 01401 pinNumToName[30]); 01402 01403 /* Save the pointer to pwm as an inaccessible attribute */ 01404 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01405 retval = int_new((uint32_t)lcd, &pn); 01406 PM_RETURN_IF_ERROR(retval); 01407 retval = dict_setItem(pattrs, PM_NONE, pn); 01408 PM_RETURN_IF_ERROR(retval); 01409 01410 NATIVE_SET_TOS(PM_NONE); 01411 return retval; 01412 01413 } 01414 01415 PmReturn_t 01416 nat_34_mbed_printf(pPmFrame_t *ppframe) 01417 { 01418 01419 pPmObj_t pself; 01420 pPmObj_t pn; 01421 pPmObj_t pattrs; 01422 PmReturn_t retval = PM_RET_OK; 01423 TextLCD *lcd; 01424 01425 /* Raise TypeError if wrong number of args */ 01426 if (NATIVE_GET_NUM_ARGS() != 2) 01427 { 01428 PM_RAISE(retval, PM_RET_EX_TYPE); 01429 return retval; 01430 } 01431 pself = NATIVE_GET_LOCAL(0); 01432 01433 /* Raise TypeError if arg is not the right type */ 01434 pn = NATIVE_GET_LOCAL(1); 01435 if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR) 01436 { 01437 PM_RAISE(retval, PM_RET_EX_TYPE); 01438 return retval; 01439 } 01440 01441 /* Get the the C++ instance */ 01442 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01443 retval = dict_getItem(pattrs, PM_NONE, &pn); 01444 PM_RETURN_IF_ERROR(retval); 01445 lcd = (TextLCD *)((pPmInt_t)pn)->val; 01446 01447 /* Write value to DAC */ 01448 pn = NATIVE_GET_LOCAL(1); 01449 lcd->printf((char const *)((pPmString_t)pn)->val); 01450 01451 NATIVE_SET_TOS(PM_NONE); 01452 return retval; 01453 01454 } 01455 01456 PmReturn_t 01457 nat_35_mbed_cls(pPmFrame_t *ppframe) 01458 { 01459 01460 pPmObj_t pself; 01461 pPmObj_t pn; 01462 pPmObj_t pattrs; 01463 PmReturn_t retval = PM_RET_OK; 01464 TextLCD *lcd; 01465 01466 /* Raise TypeError if wrong number of args */ 01467 if (NATIVE_GET_NUM_ARGS() != 1) 01468 { 01469 PM_RAISE(retval, PM_RET_EX_TYPE); 01470 return retval; 01471 } 01472 pself = NATIVE_GET_LOCAL(0); 01473 01474 /* Get the the C++ instance */ 01475 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01476 retval = dict_getItem(pattrs, PM_NONE, &pn); 01477 PM_RETURN_IF_ERROR(retval); 01478 lcd = (TextLCD *)((pPmInt_t)pn)->val; 01479 01480 /* Clear LCD */ 01481 lcd->cls(); 01482 01483 NATIVE_SET_TOS(PM_NONE); 01484 return retval; 01485 01486 } 01487 01488 PmReturn_t 01489 nat_36_mbed_locate(pPmFrame_t *ppframe) 01490 { 01491 01492 pPmObj_t pself; 01493 pPmObj_t pn; 01494 pPmObj_t pc; 01495 pPmObj_t pr; 01496 pPmObj_t pattrs; 01497 PmReturn_t retval = PM_RET_OK; 01498 TextLCD *lcd; 01499 01500 /* Raise TypeError if wrong number of args */ 01501 if (NATIVE_GET_NUM_ARGS() != 3) 01502 { 01503 PM_RAISE(retval, PM_RET_EX_TYPE); 01504 return retval; 01505 } 01506 pself = NATIVE_GET_LOCAL(0); 01507 01508 /* Raise TypeError if arg is not the right type */ 01509 pc = NATIVE_GET_LOCAL(1); 01510 pr = NATIVE_GET_LOCAL(2); 01511 if ((OBJ_GET_TYPE(pc) != OBJ_TYPE_INT) 01512 || (OBJ_GET_TYPE(pr) != OBJ_TYPE_INT)) 01513 { 01514 PM_RAISE(retval, PM_RET_EX_TYPE); 01515 return retval; 01516 } 01517 01518 /* Get the the C++ instance */ 01519 pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs; 01520 retval = dict_getItem(pattrs, PM_NONE, &pn); 01521 PM_RETURN_IF_ERROR(retval); 01522 lcd = (TextLCD *)((pPmInt_t)pn)->val; 01523 01524 /* Set the location of the LCD's cursor */ 01525 lcd->locate(((pPmInt_t)pc)->val, ((pPmInt_t)pr)->val); 01526 01527 NATIVE_SET_TOS(PM_NONE); 01528 return retval; 01529 01530 } 01531 01532 PmReturn_t 01533 nat_37_mbed_set_led(pPmFrame_t *ppframe) 01534 { 01535 01536 pPmObj_t pled; 01537 pPmObj_t pval; 01538 int32_t nled; 01539 int32_t nval; 01540 PmReturn_t retval = PM_RET_OK; 01541 01542 /* If wrong number of args, raise TypeError */ 01543 if (NATIVE_GET_NUM_ARGS() > 2) 01544 { 01545 PM_RAISE(retval, PM_RET_EX_TYPE); 01546 return retval; 01547 } 01548 01549 /* If arg is not an int, raise TypeError */ 01550 pled = NATIVE_GET_LOCAL(0); 01551 pval = NATIVE_GET_LOCAL(1); 01552 if ((OBJ_GET_TYPE(pled) != OBJ_TYPE_INT) 01553 || (OBJ_GET_TYPE(pval) != OBJ_TYPE_INT)) 01554 { 01555 PM_RAISE(retval, PM_RET_EX_TYPE); 01556 return retval; 01557 } 01558 01559 /* Get int value from the arg */ 01560 nled = ((pPmInt_t)pled)->val; 01561 nval = ((pPmInt_t)pval)->val; 01562 01563 /* Set the LED to the given value */ 01564 switch (nled) 01565 { 01566 case 1: led1 = nval; break; 01567 case 2: led2 = nval; break; 01568 case 3: led3 = nval; break; 01569 case 4: led4 = nval; break; 01570 } 01571 01572 NATIVE_SET_TOS(PM_NONE); 01573 return retval; 01574 01575 } 01576 01577 PmReturn_t 01578 nat_38_net_eth(pPmFrame_t *ppframe) 01579 { 01580 01581 PmReturn_t retval = PM_RET_OK; 01582 01583 EthernetNetIf eth( 01584 IpAddr(10,0,0,20), //IP Address 01585 IpAddr(255,0,0,0), //Network Mask 01586 IpAddr(10,0,0,1), //Gateway 01587 IpAddr(10,0,0,1) //DNS 01588 ); 01589 01590 EthernetErr ethErr = eth.setup(); 01591 if(ethErr) 01592 { 01593 01594 PM_RAISE(retval, PM_RET_EX_TYPE); 01595 return retval; 01596 01597 } 01598 NATIVE_SET_TOS(PM_NONE); 01599 return retval; 01600 01601 } 01602 01603 PmReturn_t 01604 nat_39_net_http_get(pPmFrame_t *ppframe) 01605 { 01606 01607 01608 01609 PmReturn_t retval = PM_RET_OK; 01610 pPmObj_t purl; 01611 pPmObj_t ptext; 01612 HTTPText txt; 01613 HTTPClient http; 01614 uint8_t estring[] = "error!"; 01615 uint8_t const *pestring = estring; 01616 01617 led1 = led2 = 0; 01618 01619 /* Raise TypeError if wrong number of args */ 01620 if (NATIVE_GET_NUM_ARGS() != 1) 01621 { 01622 PM_RAISE(retval, PM_RET_EX_TYPE); 01623 return retval; 01624 } 01625 purl = NATIVE_GET_LOCAL(0); 01626 01627 01628 01629 printf("the url is: \n"); 01630 01631 printf(((char *)((pPmString_t)purl)->val)); 01632 01633 01634 printf("connecting ...\n"); 01635 HTTPResult r = http.get((char *)((pPmString_t)purl)->val, &txt); 01636 printf("done\n"); 01637 if(r==HTTP_OK) 01638 { 01639 printf("OK\n"); 01640 retval = string_new(txt.gets(), &ptext); 01641 led1=1; 01642 led2=1; 01643 NATIVE_SET_TOS(ptext); 01644 01645 } 01646 else 01647 { 01648 //PM_RAISE(retval, PM_RET_EX_TYPE); 01649 printf("ERROR\n"); 01650 retval = string_new(&pestring, &ptext); 01651 led1=0; 01652 led2=1; 01653 NATIVE_SET_TOS(ptext); 01654 } 01655 return retval; 01656 01657 01658 } 01659 01660 /* native function lookup table */ 01661 PmReturn_t (* usr_nat_fxn_table[])(pPmFrame_t *) = 01662 { 01663 nat_placeholder_func, 01664 nat_01_mbed___init__, 01665 nat_02_mbed_read_u16, 01666 nat_03_mbed_read, 01667 nat_04_mbed___init__, 01668 nat_05_mbed_write_u16, 01669 nat_06_mbed_write, 01670 nat_07_mbed_read, 01671 nat_08_mbed___init__, 01672 nat_09_mbed_read, 01673 nat_10_mbed___init__, 01674 nat_11_mbed_read, 01675 nat_12_mbed_write, 01676 nat_13_mbed___init__, 01677 nat_14_mbed_read, 01678 nat_15_mbed_period, 01679 nat_16_mbed_period_ms, 01680 nat_17_mbed_period_us, 01681 nat_18_mbed_pulsewidth, 01682 nat_19_mbed_puslewidth_ms, 01683 nat_20_mbed_pulsewidth_us, 01684 nat_21_mbed___init__, 01685 nat_22_mbed_putc, 01686 nat_23_mbed_puts, 01687 nat_24_mbed_getc, 01688 nat_25_mbed___init__, 01689 nat_26_mbed_format, 01690 nat_27_mbed_frequency, 01691 nat_28_mbed_write, 01692 nat_29_mbed___init__, 01693 nat_30_mbed_frequency, 01694 nat_31_mbed_read, 01695 nat_32_mbed_write, 01696 nat_33_mbed___init__, 01697 nat_34_mbed_printf, 01698 nat_35_mbed_cls, 01699 nat_36_mbed_locate, 01700 nat_37_mbed_set_led, 01701 nat_38_net_eth, 01702 nat_39_net_http_get, 01703 };
Generated on Tue Jul 12 2022 17:07:01 by
