void sleepLcdEADog(lcdEADog* lcd) { vAHI_SpiConfigure( 2, /* number of slave select lines in use */ E_AHI_SPIM_MSB_FIRST, /* send data MSB first */ FALSE, FALSE, 0,//16MHz E_AHI_SPIM_INT_DISABLE, /* Disable SPI interrupt */ E_AHI_SPIM_AUTOSLAVE_DSABL); /* Disable auto slave select */ vAHI_DioSetOutput(0,lcd->a0pin); vAHI_SpiSelect(lcd->spicspin); vAHI_SpiStartTransfer8(0xae); vAHI_SpiWaitBusy(); vAHI_SpiStartTransfer8(0xa5); vAHI_SpiWaitBusy(); vAHI_SpiStop(); //saves 0.1mA vAHI_DioSetOutput(lcd->a0pin,0); //vAHI_DioSetOutput(lcd->spicspin,0); // vAHI_DioSetOutput(0,lcd->resetpin); }
void LcdBitBlt(uint8* buf,int scanlen,int x,int y,int w,int h,lcdEADog* lcd) { //copy an area of memory to lcd vAHI_SpiConfigure( 2, /* number of slave select lines in use */ E_AHI_SPIM_MSB_FIRST, /* send data MSB first */ FALSE, FALSE, 0,//16MHz E_AHI_SPIM_INT_DISABLE, /* Disable SPI interrupt */ E_AHI_SPIM_AUTOSLAVE_DSABL); /* Disable auto slave select */ vAHI_SpiSelect(lcd->spicspin); uint32* buf32=(uint32*)buf; if(lcd->angle!=0)x+=4; int xx,yy; int ints=w>>2; uint8 colhigh=0x10+(x>>4); uint8 collow=0x00+(x&0x0f); h=h>>3; for(yy=0;yy<h;yy++) { vAHI_DioSetOutput(0,lcd->a0pin); vAHI_SpiStartTransfer8(0xb0+yy); vAHI_SpiWaitBusy(); vAHI_SpiStartTransfer8(colhigh); vAHI_SpiWaitBusy(); vAHI_SpiStartTransfer8(collow); vAHI_SpiWaitBusy(); vAHI_DioSetOutput(lcd->a0pin,0); for(xx=0;xx< ints;xx++) { vAHI_SpiStartTransfer32(*buf32++); #if (defined JN5148 || defined JN5168 ) vAHI_SpiWaitBusy(); #else asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); asm volatile("l.nop;"); #endif } } vAHI_SpiStop(); }
/**************************************************************************** * * NAME: vDongleSetLED * * DESCRIPTION: Turns on or off the LED * * RETURNS: * void * ****************************************************************************/ void vDongleSetLED(bool state) { if(state) vAHI_DioSetOutput(0,DONGLE_STATUS_LED); else vAHI_DioSetOutput(DONGLE_STATUS_LED, 0); }
/* * write to IO * - pio: IO device pointer * - state: HIGH or LOW */ void suli_pin_write(IO_T *pio, int16 state) { if(*pio >= DO0) { uint8 u8On = 0; uint8 u8Off = 0; if(state == HAL_PIN_LOW) { u8Off = (1 << (*pio - DO0)); } else { u8On = (1 << (*pio - DO0)); } vAHI_DoSetDataOut(u8On, u8Off); } else { uint32 u32On = 0; uint32 u32Off = 0; if(state == HAL_PIN_LOW) { u32Off = (1 << (*pio)); } else { u32On = (1 << (*pio)); } vAHI_DioSetOutput(u32On, u32Off); } }
PUBLIC void vWatchdog_restart(){ #if defined WATCHDOG_INTERNAL vAHI_WatchdogRestart(); #elif defined WATCHDOG_EXTERNAL static bool isImpulse; (isImpulse) ? vAHI_DioSetOutput(WATCHDOG_IMPULSE, 0):vAHI_DioSetOutput(WATCHDOG_IMPULSE, 0); isImpulse = !isImpulse; #endif }
/*---------------------------------------------------------------------------*/ void leds_arch_init(void) { vAHI_DioSetDirection(0, LED_R | LED_G); vAHI_DioSetOutput(0, LED_R | LED_G); /* Default off */ leds = 0; }
void initLcdEADog(uint8 cs,int reset,int a0,int angle,lcdEADog* lcd) { lcd->spicspin=cs; lcd->resetpin=reset; lcd->a0pin=a0; lcd->angle=angle; uint8 config0deg[14]={0x40,0xa1,0xc0,0xa6,0xa2,0x2f,0xf8,0x00,0x27,0x81,0x16,0xac,0x00,0xaf}; uint8 config180deg[14]={0x40,0xa0,0xc8,0xa6,0xa2,0x2f,0xf8,0x00,0x27,0x81,0x16,0xac,0x00,0xaf}; vAHI_SpiConfigure( 2, /* number of slave select lines in use */ E_AHI_SPIM_MSB_FIRST, /* send data MSB first */ FALSE, FALSE, 1,//8MHz E_AHI_SPIM_INT_DISABLE, /* Disable SPI interrupt */ E_AHI_SPIM_AUTOSLAVE_DSABL); /* Disable auto slave select */ vAHI_DioSetDirection(0,lcd->resetpin); vAHI_DioSetDirection(0,lcd->a0pin); vAHI_DioSetOutput(0,lcd->resetpin); cycleDelay(16*4000); vAHI_DioSetOutput(lcd->resetpin,0); vAHI_DioSetOutput(0,lcd->a0pin); int i; vAHI_SpiSelect(lcd->spicspin); for(i=0;i<sizeof(config0deg);i++) { if(angle==180)vAHI_SpiStartTransfer8(config180deg[i]); else vAHI_SpiStartTransfer8(config0deg[i]); vAHI_SpiWaitBusy(); } vAHI_SpiStop(); }
/**************************************************************************** * * NAMES: DriverBulb_vTick * * DESCRIPTION: 10 ms Ticks from higher layer for timing * ****************************************************************************/ PUBLIC void DriverBulb_vTick(void) { #ifdef MK_JIP_DEVICE_ID /* Indicating gateway mode on LED ? */ #if (LAMP_GW_PIN < 21) { /* Gateway mode ? */ if (u16Api_GetStackMode() == 0) { /* Set output low, turning on LED */ vAHI_DioSetOutput(0, (1 << LAMP_GW_PIN)); } /* Non-gateway mode ? */ else { /* Set output high, turning off LED */ vAHI_DioSetOutput((1 << LAMP_GW_PIN), 0); } } #endif #endif }
/*---------------------------------------------------------------------------*/ void leds_arch_set(unsigned char c) { leds = c; uint32_t on = 0; uint32_t off = 0; if (leds & LEDS_GREEN) off |= E_AHI_DIO16_INT; else on |= E_AHI_DIO16_INT; if (leds & LEDS_INFRARED0) off |= E_AHI_DIO8_INT; else on |= E_AHI_DIO8_INT; if (leds & LEDS_INFRARED1) off |= E_AHI_DIO9_INT; else on |= E_AHI_DIO9_INT; if (leds & LEDS_INFRARED2) off |= E_AHI_DIO10_INT; else on |= E_AHI_DIO10_INT; vAHI_DioSetOutput(on, off); }
/**************************************************************************** * * NAME: LAMP_vInit * * DESCRIPTION: Initialises the lamp drive system * * PARAMETERS: Name RW Usage * * * RETURNS: * void * ****************************************************************************/ PUBLIC void DriverBulb_vInit(void) { bool_t bLampTimerInt = FALSE; static bool_t bInit = FALSE; if (bInit==TRUE) { /* Mimic PWM to led ? */ #if (LAMP_LED_PIN < 21) { /* Configure as output */ vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN)); /* Turn CFL lamp off */ vAHI_DioSetOutput((1 << LAMP_LED_PIN), 0); /* Register interrupt callback */ #if (JENNIC_CHIP == JN5148) || (JENNIC_CHIP == JN5148J01) vAHI_Timer1RegisterCallback(vCbTimer1); #else vAHI_Timer3RegisterCallback(vCbTimer1); #endif /* Note we want to generate interrupts */ bLampTimerInt = TRUE; } #endif /* Indicate gateway mode on LED ? */ #if (LAMP_GW_PIN < 21) { /* Configure as output */ vAHI_DioSetDirection(0, (1 << LAMP_GW_PIN)); } #endif /* Configure timer 0 to generate a PWM output on its output pin */ vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE); vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE); vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE); /********************************************/ /* Voltage Monitoring System Initialisation */ /********************************************/ gu32BusVoltage = 0; } bInit=TRUE; /* 2nd late call will be used for initialisation */ }
/*---------------------------------------------------------------------------*/ void leds_arch_set(unsigned char c) { uint32 on_mask = 0; uint32 off_mask = 0; if(c & LEDS_GREEN) { on_mask |= LED_G; } else { off_mask |= LED_G; } if(c & LEDS_RED) { on_mask |= LED_R; } else { off_mask |= LED_R; } vAHI_DioSetOutput(on_mask, off_mask); /* Both LEDs can not be switched on at the same time. Will result in both leds being OFF */ if(on_mask == (LED_R | LED_G)) { leds = 0; } else { leds = c; } }
/**************************************************************************** * * NAME: frameStartEvent * * DESCRIPTION: Handler for the frame start notification * * PARAMETERS: Name RW Usage * buff ? unused?? * * RETURNS: * * NOTES: ****************************************************************************/ void frameStartEvent(void* context,void* buff) { // Called every frame, currently 20ms frameCounter++; #ifdef JN5168 /* MAC_McpsReqRsp_s sMcpsReqRsp; MAC_McpsSyncCfm_s sMcpsSyncCfm; // Send request to remove a data frame from transaction queue sMcpsReqRsp.u8Type = MAC_MCPS_REQ_PURGE; sMcpsReqRsp.u8ParamLength = sizeof(MAC_McpsReqPurge_s); sMcpsReqRsp.uParam.sReqPurge.u8Handle = 1; vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm); */ //reset MAC MAC_MlmeReqRsp_s sMlmeReqRsp; MAC_MlmeSyncCfm_s sMlmeSyncCfm; sMlmeReqRsp.u8Type = MAC_MLME_REQ_RESET; sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqReset_s); sMlmeReqRsp.uParam.sReqReset.u8SetDefaultPib = FALSE; vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm); uint32 newchannel = getHopChannel(getSeqClock()); eAppApiPlmeSet(PHY_PIB_ATTR_CURRENT_CHANNEL, newchannel); #endif if(frameReceived==FALSE) { RX.missedFrames++; } else { RX.missedFrames=0; } //used instead of sequence number to prevent handling the same frame twice frameReceived=FALSE; // Binding check // Only do automatic bind request after 10secs incase this // was an unintended reboot in flight. // Only do if not already communicating with a tx if ((frameCounter > 500 && frameCounter < 5000) && getHopMode() == hoppingRxStartup) { // TODO - add binding button check and an option to disable auto binding uint32 channel = 0; eAppApiPlmeGet(PHY_PIB_ATTR_CURRENT_CHANNEL, &channel); if (channel == 11) { // TODO - Get rid of magic numbers uint8 packet[14]; packet[0] = 0; //no high priority data packet[1] = 0; //seq no packet[2] = 0; //chunk no packet[3] = 10; //length of message packet[4] = 0; //no route packet[5] = 16; //bind request module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation(); // TODO - can't we just memcpy the whole thing in one call? memcpy(&packet[6], &macptr->u32L, sizeof(macptr->u32L)); memcpy(&packet[10], &macptr->u32H, sizeof(macptr->u32H)); vTransmitDataPacket(packet, sizeof(packet), TRUE); } // Set the flash rate to fast to indicate binding attempts rxLEDFlashLimit = LED_FLASH_FAST; } // LED Flasher to indicate binding state. if ((getHopMode() == hoppingContinuous) && !rxLEDState) { // We have bound, set the LED on rxLEDState = TRUE; vAHI_DioSetOutput(rxHardware.ledBit, 0); } else { if (frameCounter > 5000) // We have timed out rxLEDFlashLimit = LED_FLASH_SLOW; // If the count exceeds the current limit, toggle the LED state if (++rxLEDFlashCount > rxLEDFlashLimit) { // Toggle the state flag rxLEDState = !rxLEDState; // Set the output accordingly if (rxLEDState) vAHI_DioSetOutput(rxHardware.ledBit, 0); else vAHI_DioSetOutput(0, rxHardware.ledBit); // Reset the counter for the next cycle rxLEDFlashCount = 0; } } }
inline void SET_PIN(int pin) { vAHI_DioSetOutput(0, 1 << (pin)); }
/**************************************************************************** * * NAME: Device_vInit * * DESCRIPTION: * Entry point for application * * RETURNS: * void, never returns * ****************************************************************************/ PUBLIC void Device_vInit(bool_t bWarmStart) { bool_t bFactoryReset; /* Initialise stack and hardware interfaces */ v6LP_InitHardware(); /* Cold start ? */ if (FALSE == bWarmStart) { /* Initialise exception handler */ Exception_vInit(); /* Initialise all DIO as outputs and drive low */ vAHI_DioSetDirection(0, 0xFFFFFFFE); vAHI_DioSetOutput(0, 0xFFFFFFFE); } /* Debug ? */ #ifdef DBG_ENABLE { /* Initialise debugging */ DBG_vUartInit(DEBUG_UART, DEBUG_BAUD_RATE); /* Disable the debug port flow control lines to turn off LED2 */ vAHI_UartSetRTSCTS(DEBUG_UART, FALSE); } #endif /* 6x chip family ? */ #ifdef JENNIC_CHIP_FAMILY_JN516x /* Wait for clock to stablise */ while(bAHI_Clock32MHzStable() == FALSE); #endif /* 42J01 chip ? */ #ifdef JENNIC_CHIP_JN5142J01 /* Wait for clock to stablise */ while(bAHI_Clock32MHzStable() == FALSE); #endif /* Debug */ DBG_vPrintf(TRUE, " "); DBG_vPrintf(TRUE, "\n\nDEVICE DIO"); DBG_vPrintf(DEBUG_DEVICE_FUNC, "\nDevice_vInit(%d)", bWarmStart); /* Node initialisation */ Node_vInit(bWarmStart); /* Cold start ? */ if (FALSE == bWarmStart) { /* 4x chip family ? */ #ifdef JENNIC_CHIP_FAMILY_JN514x { /* Check for factory reset using flags from flash */ bFactoryReset = Node_bTestFactoryResetFlash(); } #else { /* Check for factory reset using flags from EEPROM */ bFactoryReset = Node_bTestFactoryResetEeprom(); } #endif /* Reset the tick queue */ u8TickQueue = 0; /* Initialise PDM and MIB data */ Device_vPdmInit(); /* Apply factory reset if required */ if (bFactoryReset) Device_vReset(TRUE); /* Initialise JIP */ (void) Device_eJipInit(); } #ifdef MK_BLD_NODE_TYPE_END_DEVICE else { /* Debug */ DBG_vPrintf(DEBUG_DEVICE_FUNC, "\ni6LP_ResumeStack()"); /* Resume 6LoWPAN */ i6LP_ResumeStack(); } #endif /* Now initialised */ bInitialised = TRUE; /* Enter main loop */ Device_vMain(); /* Allow sleeping ? */ #ifdef MK_BLD_NODE_TYPE_END_DEVICE { /* Go to sleep if we exit main loop */ Device_vSleep(); } #endif }
/**************************************************************************** * * NAME: LAMP_vInit * * DESCRIPTION: Initialises the lamp drive system * * PARAMETERS: Name RW Usage * * * RETURNS: * void * ****************************************************************************/ PUBLIC void DriverBulb_vInit(void) { bool_t bLampTimerInt = FALSE; static bool_t bInit = FALSE; if (bInit == FALSE) { /* Configure DIO pins */ vAHI_DioSetDirection(0, (LAMP_ON_OFF_MASK | (1 <<LAMP_BLEEDER_PIN))); /* Turn CFL lamp off */ vAHI_DioSetOutput(0, LAMP_ON_OFF_MASK); /* Mimic PWM to led ? */ #if (LAMP_LED_PIN < 21) { /* Configure as output */ vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN)); /* Turn CFL lamp off */ vAHI_DioSetOutput(0, (1 << LAMP_LED_PIN)/*, 0*/); /* Register interrupt callback */ vAHI_Timer0RegisterCallback(vCbTimer0); /* Note we want to generate interrupts */ bLampTimerInt = TRUE; } #endif /* Configure timer 0 to generate a PWM output on its output pin */ vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE); vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE); vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE); /* turn on lamp - this is the default state */ vAHI_DioSetOutput((1 << LAMP_BLEEDER_PIN),0); vAHI_DioSetOutput(LAMP_ON_OFF_MASK,0); vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE, E_AHI_AP_INT_DISABLE, E_AHI_AP_SAMPLE_8, E_AHI_AP_CLOCKDIV_500KHZ, E_AHI_AP_INTREF); while (!bAHI_APRegulatorEnabled()); /* spin on reg not enabled */ vAHI_AdcEnable(E_AHI_ADC_SINGLE_SHOT, E_AHI_AP_INPUT_RANGE_2, ADC_USED); do { vAHI_AdcStartSample(); while(bAHI_AdcPoll()); gu32BusVoltage = ((uint32)u16AHI_AdcRead()*VBUS_MAXIMUM) >> ADC_BITS; } while (gu32BusVoltage< VBUS_TRIP_LO); vAHI_AdcDisable(); vAHI_ApConfigure(E_AHI_AP_REGULATOR_DISABLE, E_AHI_AP_INT_DISABLE, E_AHI_AP_SAMPLE_8, E_AHI_AP_CLOCKDIV_500KHZ, E_AHI_AP_INTREF); vAHI_TimerStartRepeat(LAMP_TIMER, PWM_COUNT, PWM_COUNT ); bInit = TRUE; bIsOn = TRUE; }
void AppColdStart(void) { /* initialize unaligned access handler */ UNALIGNED_ACCESS = UNALIGNED_ACCESS_HANDLER; /* initialize uart to 8N1 at 115200 baud, that gives a throughput og * ~14.4 kb/s, maxmimum packet rate on Ieee802.15.4 is 248 packets/sec at * 127 bytes payload + header, which allows to return about 50bytes on the * uart per packet. */ vAHI_UartEnable(UART); vAHI_UartReset(UART, true, true); vAHI_UartReset(UART, false, false); vAHI_UartSetControl(UART, E_AHI_UART_EVEN_PARITY, E_AHI_UART_PARITY_DISABLE, E_AHI_UART_WORD_LEN_8, E_AHI_UART_1_STOP_BIT, E_AHI_UART_RTS_HIGH); vAHI_UartSetBaudrate(UART, BAUD); vAHI_UartSetRTSCTS(UART, false); vAHI_DioSetDirection(CTS, RTS); vAHI_DioSetOutput(0x00, RTS); /* run the main loop, wait for channel number, then start reception * and packet delivery. Ack by sending "okay\n". */ while (1) { static int started = MAC_ENUM_NO_DATA; static char input[10]; static uint8_t i=0; /* write one rxd packet to uart */ if (started==MAC_ENUM_SUCCESS) { MAC_DcfmIndHdr_s *ind; if (rxq_peektype() == MCPS) { ind = rxq_peek(); if (ind->u8Type == MAC_MCPS_IND_DATA) { MAC_McpsDcfmInd_s *s = ind; uart_write(UART, (char*) &s->uParam.sIndData, sizeof(s->uParam.sIndData)); } } rxq_dequeue(); } /* read from uart into buf */ while (i<sizeof(input) && DATAREADY(UART)) { input[i] = u8AHI_UartReadData(UART); if ((i+1)==sizeof(input)) { /* buffer overrun, discard input */ memset(input, '\0', i); i = 0; } else if (input[i]=='\n' || input[i]=='\r') { /* read as channel number */ int channel; input[9] = '\0'; /* terminate string */ channel = atoi(input); /* convert string to num */ started = start_sniffer(channel); if (started != MAC_ENUM_SUCCESS) printf("not started, error code: 0x%x, see MAC_Enum_e\r\n", started); else printf("started on channel %d\r\n", channel); memset(input, '\0', i); i = 0; } else i++; } } }
inline void CLEAR_PIN(int pin) { vAHI_DioSetOutput(1 << (pin), 0); }