{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} \viewkind4\uc1\pard\f0\fs20 Notes:\par There is still approximately a 1:30 chance for the camera to still require a power cycle.\par \par Call Camera_Comm_Check() from the slow loop (auto and regular). We do it in \par Process_Data_From_Master_uP(), but our auto doesn't use a separate, independent loop.\par \par Make the following global in camera.c Initialize_Camera() so they can be reset:\par \tab unsigned char boot_initialization_flag = 1;\par \tab unsigned char initialize_flag = 1;\par \par #define PACKET_MISS_THRESH 8 // This is really looking for 2 missing packets in a row. (= #missing * 4)\par \par /*******************************************************************************\par *\par *\tab FUNCTION:\tab\tab Camera_Comm_Check()\par *\par *\tab PURPOSE:\tab\tab This detects the failure of communications with the camera.\tab\tab\par *\par *\tab CALLED FROM: \tab Process_Data_From_Master_uP()\par *\par *\tab PARAMETERS:\tab\tab none\par *\par *\tab RETURNS:\tab\tab nothing\par *\par *\tab COMMENTS:\par * MLM - Written 3/20/06\par * Several things here, such as "flag", are unnecessary and only used during debug.\par *******************************************************************************/\par #include "user_routines.h"\par #include "clock_routines.h"\par \par #define TIMEOUT 2 // (sec) Allow camera time to initialization before trying again\par // A typical camera re-initialization takes 1.2 seconds\par \par void Camera_Comm_Check(void)\par \{\par static unsigned int old_camera_t_packets=9999; // Local check\par static unsigned long camera_init_timeout=TIMEOUT;\par static unsigned char packet_err_cnt = 0;\par static char flag=TRUE;\par \par // Is the camera still communicating?\par if(old_camera_t_packets == camera_t_packets) // We didn't receive a new camera packet\par \{\par if(packet_err_cnt >= PACKET_MISS_THRESH)\par \{\par if (camera_init_timeout < Clocksec)\par \{ // Need to do periodically until power (& communication) is restored\par camera_init_timeout = Clocksec + TIMEOUT;\par Reset_Mode();\par Restart_Camera2(); \par flag = TRUE;\par printf("Restart Camera ****** Clockms=%ld\\r", Clockms);\par \}\par else // Just wait for the camera. Give it time.\par \{\par // printf("Restart: bytecount=%d, ", Camera_Serial_Port_Byte_Count());\par \}\par \}\par else\par \{\par packet_err_cnt++; // Normally see T packets at 10Hz. This count is ~4 times quicker.\par // Could check & increment at 10Hz as well...\par \}\par \}\par else\par \{\par packet_err_cnt = 0;\par old_camera_t_packets = camera_t_packets;\par if (flag) printf("Received new packet ****** Clockms=%ld\\r", Clockms);\par flag = FALSE;\par \}\par \}\par \par /*******************************************************************************\par *\par *\tab FUNCTION:\tab\tab Reset_Mode()\par *\par *\tab PURPOSE:\tab\tab Properly formats and sends a camera RS (Reset) command\par *\tab\tab\tab\tab\tab to the camera assuming camera is in either raw or ascii mode.\par * Too close together increases the camera hang rate.\par *\par *\tab CALLED FROM: Camera_Comm_Check()\par *\par *\tab PARAMETERS:\tab\tab unsigned char\par *\par *\tab RETURNS:\tab\tab nothing\par *\par *\tab COMMENTS:\tab\tab\par * MLM - Written 3/20/06\par *******************************************************************************/\par void Reset_Mode(void)\par \{\par // Raw mode\par \tab Write_Camera_Serial_Port(255); // Raw mode start flag\par \tab Write_Camera_Serial_Port('R');\par \tab Write_Camera_Serial_Port('S');\par \tab Write_Camera_Serial_Port('\\r');\par // Ascii mode\par //\tab Write_Camera_Serial_Port('R');\par //\tab Write_Camera_Serial_Port('S');\par //\tab Write_Camera_Serial_Port('\\r');\par \}\par \par \par /*******************************************************************************\par *\par *\tab FUNCTION:\tab\tab Restart_Camera2()\par *\par *\tab PURPOSE:\tab\tab This command will force a camera reinitialization\tab\tab\par *\par *\tab CALLED FROM: Camera_Comm_Check()\par *\par *\tab PARAMETERS:\tab\tab none\par *\par *\tab RETURNS:\tab\tab nothing\par *\par *\tab COMMENTS:\par * MLM - Written 2/20/06\par * Assumes the use of Kevin Watson's camera.c and serial communications code\par * Requires a couple of internal variables be made global within \par * camera.c so they may be reset.\par * unsigned char boot_initialization_flag = 1;\par * unsigned char initialize_flag = 1;\par *******************************************************************************/\par void Restart_Camera2(void)\par \{\par \tab camera_initialized = 0;\par \par //Added the following to original Restart_Camera()...\par camera_t_packets = 0; // Counts new camera T packets received\par \tab boot_initialization_flag = 1; // Reinitialize camera communication mode\par \tab initialize_flag = 1; // Reinitialize the camera.c state machine\par \}\par }