I have an STM32F103C8T6 uC and an ASIC chip. They communicate with SPI interface, ST being the Master device. On the uC lies a Firmware by the vendor of the ASIC device. I have been trying to shape it to my hardware and development tools. This is the initialization code,
/*-----------------------------------------------------------------------*/
/* init application data */
/*-----------------------------------------------------------------------*/
memset( &sDpAppl, 0, sizeof( sDpAppl ) );
and some function declarations,
#if VPC3_SERIAL_MODE
//I have already defined these externs
extern void Vpc3Write ( VPC3_ADR wAddress, uint8_t bData
);
extern uint8_t Vpc3Read ( VPC3_ADR wAddress );
extern void Vpc3MemSet ( VPC3_ADR wAddress, uint8_t bValue, uint16_t
wLength);
extern uint8_t Vpc3MemCmp ( VPC3_UNSIGNED8_PTR pToVpc3Memory1,
VPC3_UNSIGNED8_PTR pToVpc3Memory2, uint16_t wLength );
extern void CopyToVpc3 ( VPC3_UNSIGNED8_PTR pToVpc3Memory,
MEM_UNSIGNED8_PTR pLocalMemory, uint16_t wLength );
extern void CopyFromVpc3( MEM_UNSIGNED8_PTR pLocalMemory,
VPC3_UNSIGNED8_PTR pToVpc3Memory, uint16_t wLength );
#define CopyToVpc3_( _pToVpc3Memory, _pLocalMemory, _wLength )\
CopyToVpc3( _pToVpc3Memory, _pLocalMemory, _wLength )
#define CopyFromVpc3_( _pLocalMemory, _pToVpc3Memory, _wLength )\
CopyFromVpc3( _pLocalMemory, _pToVpc3Memory, _wLength )
#define Vpc3MemSet_( _pToVpc3Memory, _bValue, _wLength )\
Vpc3MemSet( _pToVpc3Memory, _bValue, _wLength )
#define Vpc3MemCmp_( _pToVpc3Memory1, _pToVpc3Memory2, _wLength )\
Vpc3MemCmp( _pToVpc3Memory1, _pToVpc3Memory2, _wLength )
#else
#define CopyToVpc3_( _pToVpc3Memory, _pLocalMemory, _wLength )\
memcpy( _pToVpc3Memory, _pLocalMemory, _wLength )
#define CopyFromVpc3_( _pLocalMemory, _pToVpc3Memory, _wLength )\
memcpy( _pLocalMemory, _pToVpc3Memory, _wLength )
#define Vpc3MemSet_( _pToVpc3Memory, _bValue, _wLength )\
memset( _pToVpc3Memory, _bValue, _wLength )
#define Vpc3MemCmp_( _pToVpc3Memory1, _pToVpc3Memory2, _wLength )\
memcmp( _pToVpc3Memory1, _pToVpc3Memory2, _wLength )
#endif /* #if VPC3_SERIAL_MODE */
I'm mostly concerned about the memset() function. In my opinion the function should initialize the ASIC chip, but to me it seems it doesnt. I am a little confused about it, or what to. I hope some more experienced eye can see what I dont.
Thank you in advance!
Related
I'm migrating a project from VC6 to VS2019. As far as I know, _far _near are for the segmented memory model access, and _cdel _ pascal are for calling convention. All of them seem only existed in VC6 and older versions. For migration, is it safe to remove them like the #else block? Thanks!
Code:
/* 関数タイプ コンパイラ依存 */
#ifdef MSDOS
#ifdef _MSC_VER /* MS-C Ver.6.0以上 */
#define FAR _far
#define NEAR _near
#define CDECL _cdecl
#define LeafFunc _fastcall _near /* nearコール */
#define NearFunc _pascal _near /* nearコール */
#define FarLeafFunc _fastcall _far /* farコール */
#define FarFunc _pascal _far /* farコール */
#define register /* register宣言は無視 */
#else /* その他 */
#define FAR
#define NEAR
#define CDECL
#define LeafFunc
#define NearFunc
#define FarLeafFunc
#define FarFunc
#endif
NareFunc is used like the following code:
void NearFunc mmInit PT0() {
//...
}
EDIT: Thanks to 9dan. I've corrected _far and _near in the post.
so I'm using 1 solution for multiple products and I need to make some kind of 'product id system' so i know what product people are using.
HEre is my attempt:
#ifdef _WIN64
#if defined(_DEBUG)
#if defined(PFW_APP_D3D_TEST)
#define PFW_PRODUCT_ID 1
#elif defined(PFW_APP_LOADER)
#define PFW_PRODUCT_ID 24
#endif
#else
#if defined(PFW_APP_D3D_TEST)
#define PFW_PRODUCT_ID 25
#elif defined(PFW_APP_LOADER)
#define PFW_PRODUCT_ID 48
//Then some nested #if here
#endif
#endif
#else
#if defined(_DEBUG)
#if defined(PFW_APP_D3D_TEST)
#define PFW_PRODUCT_ID 49
#elif defined(PFW_APP_LOADER)
#define PFW_PRODUCT_ID 72
#endif
#else
#if defined(PFW_APP_D3D_TEST)
#define PFW_PRODUCT_ID 73
#elif defined(PFW_APP_LOADER)
#define PFW_PRODUCT_ID 96
#endif
#endif
#endif
but it doesn't compile D: (no clue how to properly use this # system
so my question is, how can i fix the syntax error and is there a automated way i can generate product id's?
problem fixed...
changed from
#elif defined(PFW_APP_BF1)
#if defined(PFW_GAME_BF4)
#define PFW_PRODUCT_ID 51
#elif defined(PFW_GAME_BF1)
#define PFW_PRODUCT_ID 52
to
#elif defined(PFW_APP_BF1)
#elif defined(PFW_GAME_BF4)
#define PFW_PRODUCT_ID 51
#elif defined(PFW_GAME_BF1)
#define PFW_PRODUCT_ID 52
but sad that i couldn't use #if :D
Visual Studio defines _byteswap_uint64 and _byteswap_ulong in stdlib.h.
Am I right to assume, that this is not standard and won't compile on Linux or Darwin?
Is there a way to define these includes in a cross-platform way?
Google's CityHash source code uses this code:
https://github.com/google/cityhash/blob/8af9b8c2b889d80c22d6bc26ba0df1afb79a30db/src/city.cc#L50
#ifdef _MSC_VER
#include <stdlib.h>
#define bswap_32(x) _byteswap_ulong(x)
#define bswap_64(x) _byteswap_uint64(x)
#elif defined(__APPLE__)
// Mac OS X / Darwin features
#include <libkern/OSByteOrder.h>
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#elif defined(__sun) || defined(sun)
#include <sys/byteorder.h>
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)
#elif defined(__FreeBSD__)
#include <sys/endian.h>
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#elif defined(__OpenBSD__)
#include <sys/types.h>
#define bswap_32(x) swap32(x)
#define bswap_64(x) swap64(x)
#elif defined(__NetBSD__)
#include <sys/types.h>
#include <machine/bswap.h>
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#endif
#else
#include <byteswap.h>
#endif
I'm not aware of a cross-platform and efficient way of doing that. If you use GCC you can use the builtin byteswap like:
uint32_t __builtin_bswap32 (uint32_t x)
Those are fast but certainly not portable... unless you wrap the various versions under the appropriate ifdefs
Cheers
Francesco
Anyone got a clue how to make a vbscript popup-message/box "spawn" on top of everything and not in the background...?
This is my script: :)
Set objShell = WScript.CreateObject("WScript.Shell")
Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
intReturn = objShell.Popup("Vil du annulere shutdown?", _
20, "Shutdown om 5 minutter!", wshYesNoDialog + wshQuestionMark)
If intReturn = wshYes Then
Wscript.Echo "Shutdown annuleret."
objShell.Run "C:\ProgramData\AutoShutdown\Annuler.bat"
End If
I am very bad at vbscript, I am just using this little part for my Batch program. Any help appreciated!
It was simply by adding vbSystemModal
120, "Shutdown om 5 minutter!", wshYesNoDialog + vbSystemModal + wshQuestionMark)
The are wrappers around the API messagebox function. Just pass the numbers. Most msgbox functions just pass the numbers on so they don't need to understand them.
So use &h1000, &h2000, or &h40000
/*
* MessageBox() Flags
*/
#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
#if(WINVER >= 0x0500)
#define MB_CANCELTRYCONTINUE 0x00000006L
#endif /* WINVER >= 0x0500 */
#define MB_ICONHAND 0x00000010L
#define MB_ICONQUESTION 0x00000020L
#define MB_ICONEXCLAMATION 0x00000030L
#define MB_ICONASTERISK 0x00000040L
#if(WINVER >= 0x0400)
#define MB_USERICON 0x00000080L
#define MB_ICONWARNING MB_ICONEXCLAMATION
#define MB_ICONERROR MB_ICONHAND
#endif /* WINVER >= 0x0400 */
#define MB_ICONINFORMATION MB_ICONASTERISK
#define MB_ICONSTOP MB_ICONHAND
#define MB_DEFBUTTON1 0x00000000L
#define MB_DEFBUTTON2 0x00000100L
#define MB_DEFBUTTON3 0x00000200L
#if(WINVER >= 0x0400)
#define MB_DEFBUTTON4 0x00000300L
#endif /* WINVER >= 0x0400 */
#define MB_APPLMODAL 0x00000000L
#define MB_SYSTEMMODAL 0x00001000L
#define MB_TASKMODAL 0x00002000L
#if(WINVER >= 0x0400)
#define MB_HELP 0x00004000L // Help Button
#endif /* WINVER >= 0x0400 */
#define MB_NOFOCUS 0x00008000L
#define MB_SETFOREGROUND 0x00010000L
#define MB_DEFAULT_DESKTOP_ONLY 0x00020000L
#if(WINVER >= 0x0400)
#define MB_TOPMOST 0x00040000L
#define MB_RIGHT 0x00080000L
#define MB_RTLREADING 0x00100000L
#endif /* WINVER >= 0x0400 */
#ifdef _WIN32_WINNT
#if (_WIN32_WINNT >= 0x0400)
#define MB_SERVICE_NOTIFICATION 0x00200000L
#else
#define MB_SERVICE_NOTIFICATION 0x00040000L
#endif
#define MB_SERVICE_NOTIFICATION_NT3X 0x00040000L
#endif
#define MB_TYPEMASK 0x0000000FL
#define MB_ICONMASK 0x000000F0L
#define MB_DEFMASK 0x00000F00L
#define MB_MODEMASK 0x00003000L
#define MB_MISCMASK 0x0000C000L
Adding + 4096 to your code will also work
20, "Shutdown om 5 minutter!", wshYesNoDialog + wshQuestionMark + 4096)
Here's google search link for objShell.Popup modal 4096
As per the suggestion for the previous question I am trying to use the GetDefaultPrinter() and then to the CreateDC(), but the VC6 is consistently saying
error C2065: 'GetDefaultPrinter' : undeclared identifier
I tried Google but many faced the same problem, but none of them were fruitful. Is this a correct way to use the GetDefaultPrinter().
Winspool.h and Windows.h are included.
You probably have a very old SDK. Check if GetDefaultPrinter is defined in your winspool.h file. If not, here are the definitions:
BOOL
WINAPI
GetDefaultPrinterA (
LPSTR pszBuffer,
LPDWORD pcchBuffer
);
BOOL
WINAPI
GetDefaultPrinterW (
LPWSTR pszBuffer,
LPDWORD pcchBuffer
);
#ifdef UNICODE
#define GetDefaultPrinter GetDefaultPrinterW
#else
#define GetDefaultPrinter GetDefaultPrinterA
#endif // !UNICODE
BOOL
WINAPI
SetDefaultPrinterA (
LPCSTR pszPrinter
);
BOOL
WINAPI
SetDefaultPrinterW (
LPCWSTR pszPrinter
);
#ifdef UNICODE
#define SetDefaultPrinter SetDefaultPrinterW
#else
#define SetDefaultPrinter SetDefaultPrinterA
#endif // !UNICODE