Пример #1
0
/** \brief Error Hook function
 *
 * This fucntion is called from the os if an os interface (API) returns an
 * error. Is for debugging proposes. If called this function triggers a
 * ShutdownOs which ends in a while(1).
 *
 * The values:
 *    OSErrorGetServiceId
 *    OSErrorGetParam1
 *    OSErrorGetParam2
 *    OSErrorGetParam3
 *    OSErrorGetRet
 *
 * will provide you the interface, the input parameters and the returned value.
 * For more details see the OSEK specification:
 * http://portal.osek-vdx.org/files/pdf/specs/os223.pdf
 *
 */
void ErrorHook(void)
{
   ciaaPOSIX_printf("ErrorHook was called\n");
   ciaaPOSIX_printf("Service: %d, P1: %d, P2: %d, P3: %d, RET: %d\n",
       OSErrorGetServiceId(), OSErrorGetParam1(),
       OSErrorGetParam2(), OSErrorGetParam3(), OSErrorGetRet());
   ShutdownOS(0);
}
void dumpBuffer(uint8_t buffer[]) {
   uint16_t i;

   ciaaPOSIX_printf("===============================================================================\r\n");
   for(i = 0; i < 512; i++)
   {
      ciaaPOSIX_printf("0x%02X ", buffer[i]);
      if (((i + 1) & 0x0F) == 0) ciaaPOSIX_printf("\r\n");
   }

}
static void assert_msg(int cond, char* msg, char * file, int line)
{
   if (cond)
   {
      /* assertion is ok */
      ciaaPOSIX_printf("OK: Assert in %s:%d\n", file, line);
   }
   else
   {
      ciaaPOSIX_printf("ERROR: Assert Failed in %s:%d %s\n", file, line, msg);
   }
}
/*==================[internal functions definition]==========================*/
static void assert(int cond, char * file, int line)
{
   if (cond)
   {
      /* assertion is ok */
      ciaaPOSIX_printf("OK: Assert in %s:%d\n", file, line);
   }
   else
   {
      ciaaPOSIX_printf("Assert Failed in %s:%d\n", file, line);
   }
}
static void assert_seq(int seq, char * file, int line)
{
   static unsigned int sequence = 0;

   if (sequence == seq)
   {
      ciaaPOSIX_printf("OK: Sequence %d\n", seq);
      sequence++;
   }
   else
   {
      ciaaPOSIX_printf("ERROR: Wrong sequence: %d on %s:%d\n", seq, file, line);
   }
}
/** @brief funcion que lee los datos del sensor DHT22
 * primero realiza la inicializacion con los tiempos especificados
 *
 *luego lee 40 bits de datos que envia el sensor
 *
 *@param dhthum parametro pasado como referencia donde se modificara el valor de la humedad
 *@param dhttemp parametro pasado como referencia donde se modificara el valor de la temperatura
 */
void leer_dht22(float *dhthum,float *dhttemp){
	    int dht_pin_in;
	    float dhth,dhtt;
	    int i;
	    byte dht22_dat[5],dht22_pin_checksum;
	    for(i=0;i<5;i++){
	    dht22_dat[i]=0;
	    }
	    //START SIGNAL
	    Chip_SCU_PinMux(dht22_port,dht22_pin,SCU_MODE_PULLUP | SCU_MODE_ZIF_DIS,FUNC0); //dth22 como output
		Chip_GPIO_SetDir(LPC_GPIO_PORT,dht22_gpioPort,(1<<dht22_gpioPin),!0);
		dht22_delay_us(20);

	    Chip_GPIO_ClearValue(LPC_GPIO_PORT,dht22_gpioPort,(1<<dht22_gpioPin));

		dht22_delay_ms(5);

	    Chip_GPIO_SetValue(LPC_GPIO_PORT,dht22_gpioPort,(1<<dht22_gpioPin));

	    dht22_delay_us(30);
		//WAIT RESPONSE
	    Chip_SCU_PinMux(dht22_port,dht22_pin,SCU_MODE_PULLUP  | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS,FUNC0);
	    Chip_GPIO_SetDir(LPC_GPIO_PORT,dht22_gpioPort,(1<<dht22_gpioPin),!1);//dth22 como input
	    dht_pin_in=Chip_GPIO_GetPinState(LPC_GPIO_PORT,dht22_gpioPort,dht22_gpioPin);
	    if(dht_pin_in){
	    	ciaaPOSIX_printf("Error de inicializacion nro 1");
	    }
	    dht22_delay_us(80);
	    dht_pin_in=Chip_GPIO_GetPinState(LPC_GPIO_PORT,dht22_gpioPort,dht22_gpioPin);
	    if(!dht_pin_in){
	    	 ciaaPOSIX_printf("Error de inicializacion nro 1");
	    }
	    dht22_delay_us(70);
	    for(i=0;i<5;i++){
	    	dht22_dat[i]=leer_datos_dht();

	    }
	    dht22_pin_checksum= dht22_pin_dat[0]+dht22_pin_dat[1]+dht22_pin_dat[2]+dht22_pin_dat[3];

	    if(dht22_pin_dat[4]!=dht22_pin_checksum){
	         ciaaPOSIX_printf("\r\nDHT checksum error");
	    }

	    dhth  = (dht22_dat[0]<<8) | dht22_dat[1];
	    dhth  /= 10;
	    dhtt  = (dht22_dat[2]<<8) | dht22_dat[3];
	    dhtt /= 10;
	    *dhttemp = dhtt;
	    *dhthum = dhth;
}
Пример #7
0
void ciaaKeyboard_MainTask(void){

    static uint8_t Column, Row = 0;
    static uint8_t prev_col = 5;
    static uint8_t prev_row = 5;
    uint8_t err;

    if(0 != change_keyb_func){
    	ciaaKeyboard_FunctionInit(change_keyb_func);
    }

	err = ciaaPOSIX_ioctl(fd_keyb,KEYB_LINE_CTRL,Row);

	if(err == (-1)){
	   /* Error. ioctl function cannot be done */
	   ciaaPOSIX_printf("Error changing Active Line\n");
	   while(1);
	}


	err = ciaaPOSIX_read(fd_keyb,&Column,1);

	if(err == (-1)){
	   /* Error. read function cannot be done */
	   ciaaPOSIX_printf("Error reading Keyboard\n");
	   while(1);
	}

	if(0xFF != Column)
	{

	if((Row != prev_row) && (Column != prev_col))
	{
		err = functions[Row][Column]();
	    prev_row = Row;
	    prev_col = Column;
	}
	}

	if(MAX_COLUMN <= Row){
		Row = 0;
	}
	else{
		Row++;
	}
}
Пример #8
0
void *ciaak_malloc(size_t size)
{
   /* try to alloc memory */
   void* ret = ciaaPOSIX_malloc(size);

   /* kernel memory shall not failed :( */
   if (NULL == ret)
   {
      ciaaPOSIX_printf("Kernel out of memory :( ...\n");
      while(1)
      {
         /* TODO perform an kernel panic or like */
      }
   }

   return ret;
}