void BPL_FreeMessageBufferFromIsr(unsigned char* pBuffer) { // make sure the returned pointer is in range if (pBuffer < LOW_BUFFER_ADDRESS || pBuffer > HIGH_BUFFER_ADDRESS) { PrintString2("@ Free Buffer ISR Corrupt", CR); SetBufferPoolFailureBit(); } signed portBASE_TYPE HigherPriorityTaskWoken; // params are: queue handle, ptr to item to queue, tick to wait if full // the queue can't be full unless there is a bug, so don't wait on full if(pdTRUE != xQueueSendFromISR(QueueHandles[FREE_QINDEX], &pBuffer, &HigherPriorityTaskWoken)) { PrintString2("@ add buf to que", CR); SetBufferPoolFailureBit(); } #if 0 /* this should never be true when freeing a message buffer */ if ( HigherPriorityTaskWoken == pdTRUE ) { portYIELD(); } #endif }
void InitializeBufferPool( void ) { unsigned int i; // loop counter unsigned char* pMsgBuffer; // holds the address of the msg buffer to add to the queue // create the queue to hold the free message buffers QueueHandles[FREE_QINDEX] = xQueueCreate( ( unsigned portBASE_TYPE ) NUM_MSG_BUFFERS, ( unsigned portBASE_TYPE ) sizeof(unsigned char*) ); // Add the address of each buffer's data section to the queue for (i = 0; i < NUM_MSG_BUFFERS; i++) { // use the address of the data section so that the header is only accessed // as needed pMsgBuffer = &(BufferPool[i].buffer[0]); // We only call this at initialization so it should never fail // params: queue handle, ptr to item to queue, ticks to wait if full if ( xQueueSend( QueueHandles[FREE_QINDEX], &pMsgBuffer, DONT_WAIT ) != pdTRUE ) { PrintString2("@ Build Free Queue", CR); SetBufferPoolFailureBit(); } } }
void BPL_FreeMessageBuffer(unsigned char* pBuffer) { // make sure the returned pointer is in range if (pBuffer < LOW_BUFFER_ADDRESS || pBuffer > HIGH_BUFFER_ADDRESS) { PrintString2("@ Free Buffer Corrupt", CR); SetBufferPoolFailureBit(); } // params are: queue handle, ptr to item to queue, tick to wait if full // the queue can't be full unless there is a bug, so don't wait on full if(pdTRUE != xQueueSend(QueueHandles[FREE_QINDEX], &pBuffer, DONT_WAIT)) { PrintString2("@ add buf to que", CR); SetBufferPoolFailureBit(); } }
unsigned char* BPL_AllocMessageBuffer(void) { unsigned char * pBuffer = NULL; // params are: queue handle, ptr to the msg buffer, ticks to wait if (pdTRUE != xQueueReceive(QueueHandles[FREE_QINDEX], &pBuffer, DONT_WAIT)) { PrintString2("@ No MsgBuf", CR); SetBufferPoolFailureBit(); } else if (pBuffer < LOW_BUFFER_ADDRESS || pBuffer > HIGH_BUFFER_ADDRESS) { PrintString2("@ Invalid MsgBuf", CR); SetBufferPoolFailureBit(); } return pBuffer; }
void PrintString(float fX,float fY,u32 iColour,float fScale,const char *pString,...) { char ctext[1024]; va_list ap; va_start(ap, pString); vsprintf(ctext,pString,ap); va_end(ap); PrintString2(ctext,fX,fY,iColour,fScale); }
void PrintMessageType(tMessage *pMsg) { if (MsgInfo[pMsg->Type].Log) { #if DONT_PRINT_MESSAGE_TYPE PrintString2(MsgInfo[pMsg->Type].MsgStr, CR); #else PrintStringAndHexByte(MsgInfo[pMsg->Type].MsgStr, pMsg->Type); #endif } }
void ToggleCharging(void) { ChargeEnable = !ChargeEnable; PrintString2("- Charge ", ChargeEnable ? "Enabled" : "Disabled"); if (!ChargeEnable) { BATTERY_CHARGE_DISABLE(); BAT_CHARGE_OUT &= ~BAT_CHARGE_STATUS_OPEN_DRAIN_BITS; ChargeStatus = CHARGE_STATUS_OFF; } }
static void HelpCmdHandler(void) { PrintString("\r\n************ List of Commands ****************\r\n"); unsigned char i = 0; /* don't print the last command because it is for PC tool */ while ( i < NUMBER_OF_COMMANDS-1 ) { PrintString2((tString*)COMMAND_TABLE[i].CommandNameString,CR); i++; } }
static void ModeTimeoutHandler() { /* send a message to the host indicating that a timeout occurred */ PrintString2("- ModChgTout", CR); tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, ModeChangeIndMsg, CurrentMode); Msg.pBuffer[0] = eScModeTimeout; Msg.Length = 1; RouteMsg(&Msg); ChangeModeHandler(IDLE_MODE); }
/* this function probably belongs somewhere else */ void WhoAmI(void) { extern const char BUILD[]; extern const char VERSION[]; PrintString3("Version: ", VERSION,CR); PrintString3("Build: ", BUILD,CR); tVersion Version = GetWrapperVersion(); PrintString3("Wrapper: ", Version.pSwVer,CR); PrintString2(SPP_DEVICE_NAME,CR); PrintString("Msp430 Version "); PrintCharacter(GetMsp430HardwareRevision()); PrintString(CR); PrintStringAndDecimal("HwVersion: ", HardwareVersion()); }
unsigned char CheckClip(void) { static unsigned char Last = CLIP_INIT; unsigned char Changed = pdFALSE; unsigned char Clip = ClipOn(); if (Clip != Last) { /* change the mux settings accordingly */ ChangeMuxMode(Clip); EnableDebugUart(Clip); if (Clip == CLIP_ON) PrintString2("- Atch", CR); Changed = pdTRUE; Last = Clip; } return Changed; }
static void ShowCall(tString *pString, unsigned char Type) { static tString CallerId[15] = ""; static tTimerId NotifyTimerId = UNASSIGNED; tMessage Msg; if (Type == SHOW_NOTIF_CALLER_ID) strcpy(CallerId, pString); if (Type == SHOW_NOTIF_CALLER_NAME && *CallerId) { PrintString3("- Caller:", pString, CR); SetupMessageAndAllocateBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE); *(tSetVibrateModePayload *)Msg.pBuffer = RingTone; RouteMsg(&Msg); PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = CallPage; DrawCallScreen(CallerId, pString); // set a 5s timer for switching back to idle screen if (NotifyTimerId == UNASSIGNED) NotifyTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(NotifyTimerId, 10, NO_REPEAT, DISPLAY_QINDEX, CallerNameMsg, SHOW_NOTIF_END); StartOneSecondTimer(NotifyTimerId); } else if (Type == SHOW_NOTIF_END || Type == SHOW_NOTIF_REJECT_CALL) { PrintString2("- Call Notif End", CR); *CallerId = NULL; StopOneSecondTimer(NotifyTimerId); PageType = PAGE_TYPE_IDLE; SendMessage(&Msg, UpdateDisplayMsg, CurrentMode | MSG_OPT_UPD_INTERNAL | (CurrentMode == IDLE_MODE ? MSG_OPT_NEWUI : 0)); if (Type == SHOW_NOTIF_REJECT_CALL) SendMessage(&Msg, HfpMsg, MSG_OPT_HFP_HANGUP); } }
/* This is too slow to use */ unsigned char* BPL_AllocMessageBufferFromISR(void) { unsigned char * pBuffer = NULL; signed portBASE_TYPE HigherPriorityTaskWoken; // params are: queue handle, ptr to the msg buffer, ticks to wait if( pdTRUE != xQueueReceiveFromISR(QueueHandles[FREE_QINDEX], &pBuffer, &HigherPriorityTaskWoken )) { PrintString2("@ Alloc Buf frm Isr", CR); SetBufferPoolFailureBit(); } if ( HigherPriorityTaskWoken == pdTRUE ) { portYIELD(); } return pBuffer; }
void Init(void) { __disable_interrupt(); ENABLE_LCD_LED(); DISABLE_LCD_POWER(); /* clear shipping mode, if set to allow configuration */ PMMCTL0_H = PMMPW_H; PM5CTL0 &= ~LOCKLPM5; PMMCTL0_H = 0x00; /* disable DMA during read-modify-write cycles */ DMACTL4 = DMARMWDIS; DetermineErrata(); #ifdef BOOTLOADER /* * enable RAM alternate interrupt vectors * these are defined in AltVect.s43 and copied to RAM by cstartup */ SYSCTL |= SYSRIVECT; ClearBootloaderSignature(); #else SaveResetSource(); #endif SetupClockAndPowerManagementModule(); CheckResetCode(); if (niReset != NO_RESET_CODE) InitProperty(); InitBufferPool(); // message queue InitBattery(); CheckClip(); PrintString2("\r\n*** ", niReset == FLASH_RESET_CODE ? "FLASH" : (niReset == MASTER_RESET_CODE ? "MASTER" : "NORMAL")); PrintString3(":", niBuild, CR); ShowWatchdogInfo(); WhoAmI(); /* timer for battery checking at a regular frequency. */ BatteryTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(BatteryTimerId, BATTERY_MONITOR_INTERVAL, REPEAT_FOREVER, DISPLAY_QINDEX, MonitorBatteryMsg, MSG_OPT_NONE); StartOneSecondTimer(BatteryTimerId); InitVibration(); InitRealTimeClock(); // enable rtc interrupt LcdPeripheralInit(); DrawStartupScreen(); SerialRamInit(); /* turn the radio on; initialize the serial port profile or BLE/GATT */ CreateAndSendMessage(TurnRadioOnMsg, MSG_OPT_NONE); DISABLE_LCD_LED(); }
/*! Function to implement the BackgroundTask loop * * \param pvParameters not used * */ static void BackgroundTask(void *pvParameters) { if ( QueueHandles[BACKGROUND_QINDEX] == 0 ) { PrintString("Background Queue not created!\r\n"); } PrintString(SPP_DEVICE_NAME); PrintString2("\r\nSoftware Version ",VERSION_STRING); PrintString("\r\n\r\n"); InitializeRstNmiConfiguration(); /* * check on the battery */ ConfigureBatteryPins(); BatteryChargingControl(); BatterySenseCycle(); /* * now set up a timer that will cause the battery to be checked at * a regular frequency. */ BatteryMonitorTimerId = AllocateOneSecondTimer(); InitializeBatteryMonitorInterval(); SetupOneSecondTimer(BatteryMonitorTimerId, nvBatteryMonitorIntervalInSeconds, REPEAT_FOREVER, BACKGROUND_QINDEX, BatteryChargeControl, NO_MSG_OPTIONS); StartOneSecondTimer(BatteryMonitorTimerId); /* * Setup a timer to use with the LED for the LCD. */ LedTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(LedTimerId, ONE_SECOND*3, NO_REPEAT, BACKGROUND_QINDEX, LedChange, LED_OFF_OPTION); // Allocate a timer for wake-up iOS background BLE app CallbackTimerId = AllocateOneSecondTimer(); /****************************************************************************/ #ifdef RAM_TEST RamTestTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(RamTestTimerId, ONE_SECOND*20, NO_REPEAT, DISPLAY_QINDEX, RamTestMsg, NO_MSG_OPTIONS); StartOneSecondTimer(RamTestTimerId); #endif /****************************************************************************/ InitializeAccelerometer(); #ifdef ACCELEROMETER_DEBUG SetupMessageAndAllocateBuffer(&BackgroundMsg, AccelerometerSetupMsg, ACCELEROMETER_SETUP_INTERRUPT_CONTROL_OPTION); BackgroundMsg.pBuffer[0] = INTERRUPT_CONTROL_ENABLE_INTERRUPT; BackgroundMsg.Length = 1; RouteMsg(&BackgroundMsg); /* don't call AccelerometerEnable() directly use a message*/ SetupMessage(&BackgroundMsg,AccelerometerEnableMsg,NO_MSG_OPTIONS); RouteMsg(&BackgroundMsg); #endif /****************************************************************************/ #ifdef RATE_TEST StartCrystalTimer(CRYSTAL_TIMER_ID3,RateTestCallback,RATE_TEST_INTERVAL_MS); #endif /****************************************************************************/ for(;;) { if( pdTRUE == xQueueReceive(QueueHandles[BACKGROUND_QINDEX], &BackgroundMsg, portMAX_DELAY ) ) { PrintMessageType(&BackgroundMsg); BackgroundMessageHandler(&BackgroundMsg); SendToFreeQueue(&BackgroundMsg); CheckStackUsage(xBkgTaskHandle,"Background Task"); CheckQueueUsage(QueueHandles[BACKGROUND_QINDEX]); } } }
static void SetBufferPoolFailureBit(void) { PrintString2("@ BufPool Fail", CR); ForceWatchdogReset(); }