main.py

00001 # This file is Copyright 2006, 2007, 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 # 
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 #
00014 # Sample program for ARM target (Atmel AT91SAM7S64 chip on a AT91SAM7S-EK board)
00015 #
00016 """__NATIVE__
00017 #include "Board.h"
00018 """
00019 
00020 
00021 def get_buttons():
00022     """__NATIVE__
00023     PmReturn_t retval = PM_RET_OK;
00024     uint32_t val = 0;
00025     pPmObj_t pint;
00026 
00027     /* If wrong number of args, raise TypeError */
00028     if (NATIVE_GET_NUM_ARGS() != 0)
00029     {
00030         PM_RAISE(retval, PM_RET_EX_TYPE);
00031         return retval;
00032     }
00033 
00034     /* Collect the button input as bits in an int */
00035     if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW1_MASK) == 0)
00036     {
00037         val |= 0x01;
00038     }
00039     if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW2_MASK) == 0)
00040     {
00041         val |= 0x02;
00042     }
00043     if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW3_MASK) == 0)
00044     {
00045         val |= 0x04;
00046     }
00047     if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW4_MASK) == 0)
00048     {
00049         val |= 0x08;
00050     }
00051 
00052     retval = int_new(val, &pint);
00053     NATIVE_SET_TOS(pint);
00054 
00055     return retval;
00056     """
00057     pass
00058 
00059 
00060 def set_leds(n):
00061     """__NATIVE__
00062     pPmObj_t pn;
00063     int32_t n;
00064     PmReturn_t retval;
00065 
00066     /* If wrong number of args, raise TypeError */
00067     if (NATIVE_GET_NUM_ARGS() != 1)
00068     {
00069         PM_RAISE(retval, PM_RET_EX_TYPE);
00070         return retval;
00071     }
00072 
00073     /* If arg is not an int, raise TypeError */
00074     pn = NATIVE_GET_LOCAL(0);
00075     if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00076     {
00077         PM_RAISE(retval, PM_RET_EX_TYPE);
00078         return retval;
00079     }
00080 
00081     /* Get int value from the arg */
00082     n = ((pPmInt_t)pn)->val;
00083 
00084     /* Clear all and set the desired LEDs (active low) */
00085     AT91F_PIO_SetOutput(AT91C_BASE_PIOA, LED_MASK);
00086     AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, n);
00087     NATIVE_SET_TOS(PM_NONE);
00088     return PM_RET_OK;
00089     """
00090     pass
00091 
00092 
00093 import ipm
00094 ipm.ipm(globals())
00095 
00096 
00097 # :mode=c:

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9